Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
export const joinArray = (list = [], separator) =>
list.reduce((joinedList, item, index, {length}) => {
joinedList.push(item);
if (index < (length - 1)) {
joinedList.push(separator);
}
return joinedList;
}, []);
@jurassix

This comment has been minimized.

Copy link
Owner Author

@jurassix jurassix commented Apr 11, 2016

let list = [1, 2, 3, 4];
let joinedList = joinArray(list, 0);
console.log(joinedList);
// [1, 0, 2, 0, 3, 0, 4] 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.