Skip to content

Instantly share code, notes, and snippets.

@digitalmio
Last active September 24, 2024 17:02
Show Gist options
  • Save digitalmio/1f107bfca5f56584af9bf40ba86acf31 to your computer and use it in GitHub Desktop.
Save digitalmio/1f107bfca5f56584af9bf40ba86acf31 to your computer and use it in GitHub Desktop.

Revisions

  1. digitalmio revised this gist Sep 24, 2024. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions Leet49.ts
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,14 @@
    const test = (strs) =>
    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"]));
    console.log(test(["a"]));
  2. digitalmio revised this gist Sep 24, 2024. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions Leet49.ts
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,4 @@
    const strs = ["eat", "tea", "tan", "ate", "nat", "bat"];

    const test = () =>
    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());

    //-----

    console.log(test(["eat", "tea", "tan", "ate", "nat", "bat"]));
    console.log(test([""]));
    console.log(test(["a"]));
  3. digitalmio created this gist Sep 24, 2024.
    12 changes: 12 additions & 0 deletions Leet49.ts
    Original 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());