For x, the values repeat every 10, that is, x^{y} % 10 == (x+10)^{y} % 10.
For y, the values repeat every 4, that is, x^{y} % 10 == x^{y+4} % 10, except for the case y=0.
Why is it so? I don't know, maybe someone else can explain/prove the math. All I know is that I can use it to make the power calculations much smaller. If I need the last digit of 345435^{456,} I calculate instead the last digit of (345435%10)^{(456-1}%4+1)=5^{3=125,} which is 5.

So that's what I'm doing in the function, extracting the last two numbers out of the array, calculating the right-most digit of their power and pushing it back. I also handle the case of empty list as per the requirements, not sure why they wanted it to be 1.

We're a place where coders share, stay up-to-date and grow their careers.

Javascript:

can we have some explain please ?

Yes.

Let's look at a spreadsheet of x

^{y}% 10.For x, the values repeat every 10, that is, x

^{y}% 10 == (x+10)^{y}% 10.For y, the values repeat every 4, that is, x

^{y}% 10 == x^{y+4}% 10, except for the case y=0.Why is it so? I don't know, maybe someone else can explain/prove the math. All I know is that I can use it to make the power calculations much smaller. If I need the last digit of 345435

^{456,}I calculate instead the last digit of (345435%10)^{(456-1}%4+1)=5^{3=125,}which is 5.So that's what I'm doing in the function, extracting the last two numbers out of the array, calculating the right-most digit of their power and pushing it back. I also handle the case of empty list as per the requirements, not sure why they wanted it to be 1.