Skip to content

Instantly share code, notes, and snippets.

@MarwanShehata
Last active January 6, 2024 14:43
Show Gist options
  • Save MarwanShehata/b61487a9133f2cebbc9c06de323a9e72 to your computer and use it in GitHub Desktop.
Save MarwanShehata/b61487a9133f2cebbc9c06de323a9e72 to your computer and use it in GitHub Desktop.
function joinElements(arr, joinString) {
function recurse(i, resultSoFar) {
resultSoFar += arr[i];
console.log(resultSoFar);
if (i === arr.length - 1) {
return resultSoFar;
} else {
return recurse(i + 1, resultSoFar + joinString);
}
}
return recurse(0, "");
}
joinElements(["s", "cr", "et cod", " :) :)"], "e");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment