Skip to content

Instantly share code, notes, and snippets.

@haykam821
Last active April 6, 2017 20:30
Show Gist options
  • Save haykam821/c859ea9ddf435c35704c5d420ff01fc4 to your computer and use it in GitHub Desktop.
Save haykam821/c859ea9ddf435c35704c5d420ff01fc4 to your computer and use it in GitHub Desktop.
// Example using function
alert(joinSeparated(['test','+','test'],'+'));
// The function, copy and paste this
function joinSeparated(array, separator) {
for (i in array){
try {
i--;
if (array[i]==separator){
array[i]=array[i-1]+array[i]+array[i+1];
array.splice(i+1,1);
array.splice(i-1,1);
}
} catch (err) {
console.log('Joiner error:' + err)
}
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment