Middle+
/* * Write a function strjoin that joins strings with a separator. */ function strjoin() { // code here } console.log(strjoin('.', 'a', 'b', 'c')) // 'a.b.c' console.log(strjoin('-', 'a', 'b', 'c', 'd', 'e', 'f')) // 'a-b-c-d-e-f'
sobes.tech AI
Answer from AI
The strjoin function should take a separator as the first argument, followed by any number of strings, and return their concatenation using this separator.
Example implementation in JavaScript using the rest operator and the join method:
function strjoin(separator, ...strings) {
return strings.join(separator);
}
console.log(strjoin('.', 'a', 'b', 'c')) // 'a.b.c'
console.log(strjoin('-', 'a', 'b', 'c', 'd', 'e', 'f')) // 'a-b-c-d-e-f'