Timeline for Accumulate the charAt(*) for each n
Current License: CC BY-SA 3.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 1, 2017 at 21:51 | vote | accept | TurtleWolfe | ||
Jul 1, 2017 at 21:38 | answer | added | janos | timeline score: 5 | |
Jul 1, 2017 at 20:58 | history | edited | Jamal | CC BY-SA 3.0 |
edited body; edited title
|
Jul 1, 2017 at 20:34 | comment | added | Barmar |
Any time you find yourself creating variables like digitOne , digitTWO , etc. you should be using an array. Then you won't have an arbitrary limit on the number of digits.
|
|
Jul 1, 2017 at 20:29 | answer | added | ljeabmreosn | timeline score: 5 | |
Jul 1, 2017 at 20:09 | comment | added | Ben Steffan | I don't actually speak JavaScript, but the general algorithm you would see implemented (in any language) goes like this: while number not 0: result = result + num % 10; num = num / 10 Where '%' is the modulo operator | |
Jul 1, 2017 at 20:07 | comment | added | Ben Steffan | What you are trying to do is called calculating a digit sum. | |
Jul 1, 2017 at 19:53 | history | asked | TurtleWolfe | CC BY-SA 3.0 |