Skip to content

Instantly share code, notes, and snippets.

@hashedhyphen
Created March 20, 2019 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hashedhyphen/b0907100b5c5c9215cf0e8599ca8e332 to your computer and use it in GitHub Desktop.
Save hashedhyphen/b0907100b5c5c9215cf0e8599ca8e332 to your computer and use it in GitHub Desktop.
function intersperse(array, item) {
if (array.length < 2) {
return array
}
return array.reduce(
(acc, cur, i) => i === array.length - 1 ? [...acc, cur] : [...acc, cur, item],
[]
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment