Skip to content

Instantly share code, notes, and snippets.

@Gabri3l
Created August 16, 2016 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gabri3l/25644e6cbc4709790565b729d39f7e4a to your computer and use it in GitHub Desktop.
Save Gabri3l/25644e6cbc4709790565b729d39f7e4a to your computer and use it in GitHub Desktop.
/*
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