Created
January 18, 2023 02:26
-
-
Save benjaminudoh10/7e0f2fef90c2fc169884b0cdf40a0ae4 to your computer and use it in GitHub Desktop.
Incomplete solution to https://www.codewars.com/kata/5511b2f550906349a70004e1/train/javascript
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
function lastDigit(str1, str2) { | |
if (str2 === "1") return parseInt(str1[str1.length - 1]) | |
if (str2 === "0") return 1 | |
if (str1 === "0" && str2 === "0") return 1 | |
if (str1.endsWith("0")) return 0 | |
if (str1.endsWith("1")) return 1 | |
if (str1.endsWith("2")) { | |
return [6, 2, 4, 8][str2 % 4] | |
} | |
if (str1.endsWith("3")) { | |
return [1, 3, 9, 7][str2 % 4] | |
} | |
if (str1.endsWith("4")) { | |
return [6, 4][str2 % 2] | |
} | |
if (str1.endsWith("5")) return 5 | |
if (str1.endsWith("6")) return 6 | |
if (str1.endsWith("7")) { | |
return [1, 7, 9, 3][str2 % 4] | |
} | |
if (str1.endsWith("8")) { | |
return [6, 8, 4, 2][str2 % 4] | |
} | |
if (str1.endsWith("9")) { | |
if (str2 % 2) return 9 | |
else return 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment