Skip to content

Instantly share code, notes, and snippets.

@jelmervdl
Created January 25, 2023 10:53
Show Gist options
  • Select an option

  • Save jelmervdl/69ab3fe42704d9eb4d36089619c0c790 to your computer and use it in GitHub Desktop.

Select an option

Save jelmervdl/69ab3fe42704d9eb4d36089619c0c790 to your computer and use it in GitHub Desktop.

Revisions

  1. jelmervdl created this gist Jan 25, 2023.
    7 changes: 7 additions & 0 deletions oxford-comma.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    const joinA = (strs) => [...strs.slice(0,-1), `and ${strs[strs.length-1]}`].join(', ');
    const joinB = (strs) => `${strs.slice(0,-1).join(', ')} and ${strs[strs.length-1]}`;

    const strs = new Array(10).fill().map((_, i) => (i + 1).toString());
    console.log(joinA(strs))
    console.log(joinB(strs))