Created
December 28, 2018 02:51
-
-
Save iwfan/8bfe95d992813ef9a0680260c21ee525 to your computer and use it in GitHub Desktop.
Array separator
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 characters
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