Created
August 16, 2016 20:41
-
-
Save Gabri3l/25644e6cbc4709790565b729d39f7e4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Return the last digit of str1 to the power of str2. They can potentially be two very big values. | |
*/ | |
function lastDigit(str1, str2){ | |
if (+str2 === 0) return 1; | |
if (+str1.slice(-1) === 0 && str1.length > 1) return 0; | |
return Math.pow(+str1.slice(-1), +str2.slice(-2)%4 || 4) % 10; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment