← Back to challenges

Harshad Numbers

JavaScriptHardnumbersmathstringsvalidation

Instructions

A number n is a Harshad (also called Niven) number if it is divisible by the sum of its digits. For example, 666 is divisible by 6 + 6 + 6, so it is a Harshad number.

Write a function to determine whether the given number is a Harshad number.

Examples

isHarshad(209) ➞ true

isHarshad(41) ➞ false

isHarshad(12255) ➞ true

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Simple Circle Collision Detection