Show steps? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Show steps?

https://code.sololearn.com/We1rSdjApTeH/?ref=app How can I display the steps for the equation? For example Input:135 Equation: 1^1+3^2+5^3 1^1 = 1 3^2 = 9 5^3 = 125 1+9+125=135 Tbh I haven't tried anything yet. But I probably won't have time to figure it out today.

30th Sep 2018, 9:16 PM
Daniel Cooper
Daniel Cooper - avatar
2 Answers
+ 6
loop each letter to get it's position. You may need to convert it to string to do that. const input = 135; const string = input.toString(); const result = 0; for(var a = 0; a < string.length; a++) { const position = a + 1; const num = parseInt(string[a]); result += Math.pow(num, position); }
30th Sep 2018, 10:31 PM
Toni Isotalo
Toni Isotalo - avatar