Remove isArmstrongNumber
This commit is contained in:
@ -1,20 +0,0 @@
|
||||
---
|
||||
title: isArmstrongNumber
|
||||
tags: math,beginner
|
||||
---
|
||||
|
||||
Checks if the given number is an Armstrong number or not.
|
||||
|
||||
Convert the given number into an array of digits. Use the exponent operator (`**`) to get the appropriate power for each digit and sum them up. If the sum is equal to the number itself, return `true` otherwise `false`.
|
||||
|
||||
```js
|
||||
const isArmstrongNumber = digits =>
|
||||
(arr => arr.reduce((a, d) => a + parseInt(d) ** arr.length, 0) == digits)(
|
||||
(digits + '').split('')
|
||||
);
|
||||
```
|
||||
|
||||
```js
|
||||
isArmstrongNumber(1634); // true
|
||||
isArmstrongNumber(56); // false
|
||||
```
|
||||
@ -1,11 +0,0 @@
|
||||
const {isArmstrongNumber} = require('./_30s.js');
|
||||
|
||||
test('isArmstrongNumber is a Function', () => {
|
||||
expect(isArmstrongNumber).toBeInstanceOf(Function);
|
||||
});
|
||||
test('isArmstrongNumber returns true', () => {
|
||||
expect(isArmstrongNumber(1634)).toBeTruthy();
|
||||
});
|
||||
test('isArmstrongNumber returns false', () => {
|
||||
expect(isArmstrongNumber(56)).toBeFalsy();
|
||||
});
|
||||
Reference in New Issue
Block a user