Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const getGets = (arr) => {
- let index = 0;
- return () => {
- const toReturn = arr[index];
- index += 1;
- return toReturn;
- };
- };
- // this is the test
- const test = ['3'];
- const gets = this.gets || getGets(test);
- const print = this.print || console.log;
- let value = gets();
- let sum = 0;
- let valueCleared = 0;
- let finalSum = 0;
- const crooked = (n) => {
- let arr = n
- .replace(/\D/g, '')
- .split('')
- .map(Number);
- do {
- sum = arr.reduce((acc, el) => {
- acc += el;
- return acc;
- });
- arr = sum.toString().split('').map(Number);
- } while (arr.length > 1);
- return sum;
- };
- print(crooked(value));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement