Last active
May 13, 2020 12:35
-
-
Save mu-hun/ac04dde5ca8c69f4dd1828cfb5c930f8 to your computer and use it in GitHub Desktop.
palindrome
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 palindrome<T extends string | string[]>(array: T) { | |
for (let start = 0, end = array.length - 1; start < end; start++, end--) { | |
if (array[start] !== array[end]) return false | |
} | |
return true | |
} | |
console.assert(palindrome('HIH')) | |
console.assert(palindrome('nan nan nan')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment