Last active
April 6, 2017 20:30
-
-
Save haykam821/c859ea9ddf435c35704c5d420ff01fc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example using function | |
alert(joinSeparated(['test','+','test'],'+')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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