Skip to content

Commit 44f683e

Browse files
authored
Create 048.js
1 parent 7c6f8a0 commit 44f683e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

048.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//n at the end of numbers because we're using BigInt
2+
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt for reference
3+
4+
let sum = 0n; //cumulative variable to add to
5+
6+
for (let i = 1n; i <= 1000n; i++) {
7+
sum += i ** i; //add self-power (i^i) to the cumulative sum
8+
}
9+
10+
console.log(sum.toString().substring(sum.toString().length - 10)) //print last 10 digits of sum as a string

0 commit comments

Comments
 (0)