Advertisement
nikolayneykov

Untitled

Oct 27th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const getGets = (arr) => {
  2.   let index = 0;
  3.  
  4.   return () => {
  5.     const toReturn = arr[index];
  6.     index += 1;
  7.     return toReturn;
  8.   };
  9. };
  10. // this is the test
  11. const test = ['3'];
  12.  
  13. const gets = this.gets || getGets(test);
  14. const print = this.print || console.log;
  15.  
  16. let value = gets();
  17.  
  18. let sum = 0;
  19. let valueCleared = 0;
  20. let finalSum = 0;
  21.  
  22. const crooked = (n) => {
  23.   let arr = n
  24.     .replace(/\D/g, '')
  25.     .split('')
  26.     .map(Number);
  27.  
  28.   do {
  29.     sum = arr.reduce((acc, el) => {
  30.       acc += el;
  31.  
  32.       return acc;
  33.     });
  34.  
  35.     arr = sum.toString().split('').map(Number);
  36.   } while (arr.length > 1);
  37.  
  38.   return sum;
  39. };
  40.  
  41. print(crooked(value));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement