Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (() => {
- const process = (_num, flag = false, history = []) => {
- let num = String(_num);
- let arr = num.split('');
- history.push(arr);
- let sum = arr
- .map(itm => parseInt(itm))
- .reduce((sum, current) => sum + current);
- if(!sum) return false;
- if(String(sum).length > 1){
- return process(sum, flag, history)
- }
- return !flag ? sum: {sum, history};
- };
- let res = process(999999999999991, true);
- console.log(res);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement