Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. (() => {
  2. const process = (_num, flag = false, history = []) => {
  3. let num = String(_num);
  4. let arr = num.split('');
  5. history.push(arr);
  6. let sum = arr
  7. .map(itm => parseInt(itm))
  8. .reduce((sum, current) => sum + current);
  9. if(!sum) return false;
  10. if(String(sum).length > 1){
  11. return process(sum, flag, history)
  12. }
  13. return !flag ? sum: {sum, history};
  14. };
  15. let res = process(999999999999991, true);
  16. console.log(res);
  17.  
  18. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement