Last active
September 24, 2024 17:02
-
-
Save digitalmio/1f107bfca5f56584af9bf40ba86acf31 to your computer and use it in GitHub Desktop.
Revisions
-
digitalmio revised this gist
Sep 24, 2024 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,14 @@ const test = (strs: string[]) => Object.values( strs.reduce((acc, el) => { const key = el.split("").sort().join(""); acc[key] = [...(acc[key] || []), el].sort(); return acc; }, {} as Record<string, string[]>) ).sort((a, b) => a.length - b.length); // ======================== console.log(test(["eat", "tea", "tan", "ate", "nat", "bat"])); console.log(test([""])); console.log(test(["a"])); -
digitalmio revised this gist
Sep 24, 2024 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,4 @@ const test = (strs) => Object.values( strs.reduce((acc, el) => { const key = el.split("").sort().join(""); @@ -9,4 +7,9 @@ const test = () => }, {}) ).sort((a, b) => a.length - b.length); //----- console.log(test(["eat", "tea", "tan", "ate", "nat", "bat"])); console.log(test([""])); console.log(test(["a"])); -
digitalmio created this gist
Sep 24, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ const strs = ["eat", "tea", "tan", "ate", "nat", "bat"]; const test = () => Object.values( strs.reduce((acc, el) => { const key = el.split("").sort().join(""); acc[key] = [...(acc[key] || []), el].sort(); return acc; }, {}) ).sort((a, b) => a.length - b.length); console.log(test());