My question looks at the following code,
const arr = ['0', '1', '7', '18', '10', '19', '15'];
const my_obj = {
[Symbol.iterator]: function*() {
for(let index of arr) {
yield `${index}`;
}
}
};
const all = [...my_obj]
.map(i => parseInt(i, 8))
The output is,
(
0,
1,
7,
1,
8,
1,
13
)
When arr is changed to arr = ['0', '1', '24', '26', '28', '29', '17'];
The output is,
(
0,
1,
20,
22,
2,
2,
15
)
Now, I notice a pattern, and I can't explain why,
for 0, 1, and 7, the output is just 0, 1, 7. For 10, 15 and 17, the output is 8, 13 and 15 (a difference of 2). For 18 and 19, the output is 1. For 24 and 26, the output is 20 and 22 (a difference of 4), and for 28 and 29, the output is 2. So, for digit's between 10-20, there's a difference of 2, and for digit's 20-30, there's a difference of 4 (went up by 2). Also, for digit's between 10-20 with digit's 18 and 19, the value is 1, but for digit's between 20-30 with digit's 28 and 29, the value is 2 (increased by 1).
I'm having trouble why this is happening. Could someone please clearly present the reasoning for this functionality?