Skip to content

Instantly share code, notes, and snippets.

View jagomf's full-sized avatar

Jago jagomf

View GitHub Profile
@jagomf
jagomf / listJoiner.js
Last active August 29, 2015 14:20
Turns an array of items into a String of items separated by middleJoiner and endJoiner
/*
var fruits = ['apple', 'orange', 'banana', 'pear'],
middleJoiner = ', ',
endJoiner = ' and ',
result = listJoiner(fruits, middleJoiner, endJoiner);
*/
// result will be this string: 'apple, orange, banana and pear'
//Iterative way
function listJoinerIter(elems, middleJoiner, endJoiner) {