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.
2 Antworten
+ 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);
}