I want to simulate join function using reduce in javascript.And here is the code:
function join(arr, separator) {
return arr.reduce((a, item) => (a ? a + separator + item : item), "");
}
But when i try join(['', '', ''], ',')
, the code produce ''. I don't understand why my code doesn't output ',,'.