Skip to content

Instantly share code, notes, and snippets.

@tokland
Last active October 22, 2018 22:34
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 tokland/db217277fd910f62537105adeaa0b4e3 to your computer and use it in GitHub Desktop.
Save tokland/db217277fd910f62537105adeaa0b4e3 to your computer and use it in GitHub Desktop.
// intersperse(items: any[], value: any): any[]
// http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:intersperse
const _ = require('lodash');
_.mixin({
intersperse(array, sep) {
return _(array)
.flatMap(x => [x, sep])
.slice(0, -1)
.value();
},
});
// _.intersperse(["a", "b", "c"], "-")
// > ["a", "-", "b", "-", "c"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment