Skip to content

Instantly share code, notes, and snippets.

@nblackburn
Last active November 5, 2024 22:27
Show Gist options
  • Select an option

  • Save nblackburn/6f41e0596ef1d5e15d59de4e796ea84c to your computer and use it in GitHub Desktop.

Select an option

Save nblackburn/6f41e0596ef1d5e15d59de4e796ea84c to your computer and use it in GitHub Desktop.

Revisions

  1. nblackburn revised this gist Nov 5, 2024. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions isPalindrome.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,11 @@
    const isPalindrome = (value) => {
    const chars = value.split('');
    const chars = value.replace(/[^a-zA-Z0-9]/g, '').toLowerCase().split('');

    return chars.every((char, index) => char === chars[chars.length - 1 - index]);
    for (let index = 0; index < chars.length / 2; index++) {
    if (chars[index] !== chars[chars.length - 1 - index]) {
    return false;
    }
    }

    return true;
    };
  2. nblackburn created this gist Feb 10, 2022.
    11 changes: 11 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    Checks if a given word is a palindrome.

    ## Usage

    ```javascript
    const tests = ['hannah', 'anna', 'kayak', 'apple', 'mom', 'wow', 'rotator', 'radar']

    tests.forEach((test) => {
    console.log('IS_PALINDROME', test, isPalindrome(test));
    });
    ```
    5 changes: 5 additions & 0 deletions isPalindrome.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    const isPalindrome = (value) => {
    const chars = value.split('');

    return chars.every((char, index) => char === chars[chars.length - 1 - index]);
    };