mirror of
https://github.com/house-of-vanity/sum_counter.git
synced 2025-08-21 15:57:19 +00:00
some
This commit is contained in:
21
som.js
Normal file
21
som.js
Normal file
@@ -0,0 +1,21 @@
|
||||
console.time('st')
|
||||
const getNumSum = (num) => {
|
||||
let buf = num
|
||||
let res = 0;
|
||||
|
||||
while (buf > 0) {
|
||||
res = res + buf % 10
|
||||
buf = Math.floor(buf / 10)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
const end = 1000000000
|
||||
let result = 0
|
||||
for(let i = 1; i <= end; i++){
|
||||
result += getNumSum(i)
|
||||
}
|
||||
|
||||
|
||||
console.log(result)
|
||||
console.timeEnd('st')
|
Reference in New Issue
Block a user