Skip to content

Instantly share code, notes, and snippets.

@mu-hun
Last active May 13, 2020 12:35
Show Gist options
  • Save mu-hun/ac04dde5ca8c69f4dd1828cfb5c930f8 to your computer and use it in GitHub Desktop.
Save mu-hun/ac04dde5ca8c69f4dd1828cfb5c930f8 to your computer and use it in GitHub Desktop.
palindrome
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