Skip to content

Instantly share code, notes, and snippets.

@secretgspot
Last active December 30, 2019 22:00
Show Gist options
  • Save secretgspot/46acb7802761e30aa0380445de4e2ce6 to your computer and use it in GitHub Desktop.
Save secretgspot/46acb7802761e30aa0380445de4e2ce6 to your computer and use it in GitHub Desktop.
// https://www.youtube.com/watch?v=Wim9WJeDTHQ
let steps = 0;
const per = (num) => {
steps++;
let digits = [...String(num)].map(i => Number(i));
let result = digits.reduce((acc, cur) => acc * cur);
if (result == 0
|| String(result).length == 1
|| Number.isNaN(result)) {
console.log(result);
console.log('Steps:', steps);
return;
};
console.log(result);
per(result);
}
per(277777788888899); // 11 steps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment