Skip to content

Instantly share code, notes, and snippets.

@alex-hladun
Created May 26, 2020 22:51
Show Gist options
  • Save alex-hladun/62f1c8b9ca653e1042fd913aff82a023 to your computer and use it in GitHub Desktop.
Save alex-hladun/62f1c8b9ca653e1042fd913aff82a023 to your computer and use it in GitHub Desktop.
Joins a string of characters together in a string.
/*
* Write a function that joins the contents of conceptList together
* into one String, concepts, with each list item separated from
* the previous by a comma.
*
* To implement this we'll create a joinList function which will take
* in any array of strings return a comma-separated string.
*/
let joinList = function(list) {
let str = "";
for (let i = 0; i <= list.length - 1; i++) {
for (let j = 0; j <= list[i].length - 1; j++) {
str += list[i][j];
}
if (i !== (list.length - 1)) {
str += ", ";
}
}
return str;
};
console.log(`Today I learned about ${joinList(["gists", "types", "operators", "iteration", "problem solving"])}.`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment