Skip to content

Instantly share code, notes, and snippets.

@iwfan
Created December 28, 2018 02:51
Show Gist options
  • Save iwfan/8bfe95d992813ef9a0680260c21ee525 to your computer and use it in GitHub Desktop.
Save iwfan/8bfe95d992813ef9a0680260c21ee525 to your computer and use it in GitHub Desktop.
Array separator
function separator(array, delimiter) {
let len = array.length;
const arr = new Array(len * 2 - 1).fill(0);
return arr.reduceRight((p, _, i) =>
[
i % 2 === 0
? array[--len]
: delimiter,
...p
]
, [])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment