CoDEVIANT #12 (4/12/19)

Guess who’s back, back again.
nuff said
No, not THAT Red Pill, fuck those people. 😡
That’s better.
You don’t feel personally attacked, WE feel personally attacked…by me….hmm…oh boy, I need therapy.
persistence(39) === 3 // because 3*9 = 27, 2*7 = 14, 1*4=4// and 4 has only one digitpersistence(999) === 4 // because 9*9*9 = 729, 7*2*9 = 126,// 1*2*6 = 12, and finally 1*2 = 2persistence(4) === 0 // because 4 is already a one-digit number
function persistence(num) {   console.log(num);//we need to create a counter that starts at zero   let counter = 0;function recursiveWork(num){//we need to turn num into a string and the into an array   num = num.toString().split(‘’);   console.log(num);//we need to multiply each member of the array from left to right by each other//we will need a variable to hold the value of the forEach’s work   let runningTally = 1;   num.forEach((currentValue)=>{      runningTally *= currentValue;      console.log(runningTally);   })console.log(‘runningTally is: ‘ + runningTally);console.log(‘counter is currently:’ + counter);//IF the final product is one character long, we return counter which is zero   if(runningTally.toString().length == 1) {      return counter;   } else {//ELSE (should the final product be longer than one character) we increment the counter//by one and then turn the final product into a string and into an array (repeat)      counter++;      recursiveWork(runningTally);   }}   if(num.toString().length == 1){      return counter;   } else {      counter ++;   recursiveWork(num);   }return counter;}
let counter = 0;
num.toString()
num.toString().length
if( num.toString().length == 1 ) {//we all float down here.... shut up, Pennywise.}
counter++ ; //shorthand way of doing counter = counter + 1;
You know HE’s happy.
Shit, wrong ‘work’ but also really really really good.
function recursiveWork(num){//we need to turn num into a string and the into an array   num = num.toString().split(‘’);   console.log(num);//we need to multiply each member of the array from left to right by each other//we will need a variable to hold the value of the forEach’s work   let runningTally = 1;   num.forEach((currentValue)=>{      runningTally *= currentValue;      console.log(runningTally);   })   console.log(‘runningTally is: ‘ + runningTally);   console.log(‘counter is currently:’ + counter);//IF the final product is one character long, we return counter which is zero   if(runningTally.toString().length == 1) {      return counter;   } else {//ELSE (should the final product be longer than one character) we increment the counter//by one and then turn the final product into a string and into an array (repeat)      counter++;      recursiveWork(runningTally);   }}
num = num.toString().split(‘’); // 36 becomes ’36’ before turning into [‘3’,’6’]
My favorite season is spring, I collect stamps, my favorite sexual position is missionary, and my favorite super hero is Superman
runningTally *= currentValue;// shorthand for runningTally = runningTally * currentValue;
and that’d be it.
if(runningTally.toString().length == 1) {   return counter;   } else {   counter++;   recursiveWork(runningTally);}
I love the smell of recursion in the morning.
function persistence(num) {   let counter = 0;   function recursiveWork(num){      num = num.toString().split(‘’);      let runningTally = 1;      num.forEach((currentValue)=>{         runningTally *= currentValue;      })      if(runningTally.toString().length == 1) {         return counter;      } else {         counter++;         recursiveWork(runningTally);      }}   if(num.toString().length == 1){      return counter;   } else {      counter ++;      recursiveWork(num);   }return counter;}
function persistence(num) {   var times = 0;   num = num.toString();   while (num.length > 1) {   times++; num = num.split(‘’).map(Number).reduce((a, b) => a * b).toString();}return times;}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adrian Rosales

Adrian Rosales

is a web developer, opera singer, actor, and lover of cats. (adrian-rosales.tech)