Skip to content

Instantly share code, notes, and snippets.

@volkofdev
Last active September 16, 2020 08:02
Show Gist options
  • Select an option

  • Save volkofdev/ac61c233a67bed300f87c4c2222054c5 to your computer and use it in GitHub Desktop.

Select an option

Save volkofdev/ac61c233a67bed300f87c4c2222054c5 to your computer and use it in GitHub Desktop.

Revisions

  1. volkofdev renamed this gist Sep 16, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. volkofdev created this gist Sep 16, 2020.
    20 changes: 20 additions & 0 deletions anagramArrayJavaScript.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    function checkAnagram(anagramArray) {
    let result = {};
    if (anagramArray.length <= 1) {
    return false;
    } else {
    for (let word of anagramArray) {
    let cleansed = word.split("").sort().join("");
    if (result[cleansed]) {
    result[cleansed].push(word);
    } else {
    result[cleansed] = [word];
    }
    }
    if (Object.values(result).length === 1) {
    return true;
    } else {
    return false;
    }
    }
    }