Armstrong numbers
This commit is contained in:
8
typescript/armstrong-numbers/armstrong-numbers.ts
Normal file
8
typescript/armstrong-numbers/armstrong-numbers.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export const isArmstrongNumber = (candidate: bigint | number): boolean =>
|
||||
candidate
|
||||
.toString()
|
||||
.split('')
|
||||
.map(BigInt)
|
||||
.reduce((result, value, _index, arr) =>
|
||||
result + (value ** BigInt(arr.length)), 0n
|
||||
) === BigInt(candidate);
|
||||
Reference in New Issue
Block a user