Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sumDigits(num) {
- let strArray = num.toString().split('');
- let sum = 0;
- for (let i = 0; i < strArray.length; i++) {
- sum += Number(strArray[i]);
- }
- console.log(sum);
- }
- Тарикатско решение:)
- function sumDigits(num) {
- console.log(num.toString().split('').reduce((a, b) => Number(a) + Number(b), 0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement