Created
May 26, 2020 22:51
-
-
Save alex-hladun/62f1c8b9ca653e1042fd913aff82a023 to your computer and use it in GitHub Desktop.
Joins a string of characters together in a string.
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
/* | |
* 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