Skip to content

Commit e2d0139

Browse files
author
Mohan
committed
count the numbers have same first and last digits
1 parent 03cebf3 commit e2d0139

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

first_last_same_digits.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Given a range of numbers, count the numbers which have same first and last digits
2+
// Ex: Between 7 and 20 such numbersare 8,9 and 11
3+
let firstDigit = 0
4+
let lastDigit = 0
5+
6+
for (let i = 8; i < 20; i++) {
7+
if (i < 10) {
8+
firstDigit = i
9+
lastDigit = i
10+
} else {
11+
firstDigit = Math.floor(i / 10)
12+
lastDigit = i % 10
13+
}
14+
15+
if (firstDigit === lastDigit) {
16+
console.log(i)
17+
}
18+
}

0 commit comments

Comments
 (0)