I am trying to understand for loops totally. I made my research and understand a little.
I Know loops like
for(var i = 0; i < 5; i++) { console.log(i) }
Which means continue to increment i starting from 0 as log as i is less than 5
I also know loops like
var a = [];
a[5] = 5;
for (var x in a) {
console.log(x);
}
Which means loop for x in a and would log 5;
Was searching playing around researching and then i see something like
function aNumber() {
var aInt = 521;
var intString = aInt.toString();
var intLength = intString.length;
var result = 0;
for (var i in intString) {
result += Math.pow((+intString[i]), intLength);
}
console.log(result);
//...
}
aNumber();
I understand the conversion of int to string. But the loop is new to me.
I know what the Math.pow() function does like it take to parameters (Math.pow(2,2) is same as 2**2) and the + in +intString passes the string as an int What i don't really understand is this part here
result += Math.pow((+intString[i]), intLength);
Its making the whole loop look confusing.
Can someone help explain it for me in simple terms just like i explained the others? Thanks
aIntinstead of leaving those periods.0,1,2as properties - but it could have more than that with bad code :presult +=that confuses you? that's just shorthand forresult = result +