Middle+
Rewrite the strjoin function without using rest parameters, using the arguments object instead.
sobes.tech AI
Answer from AI
Here is an example of the strjoin function, which concatenates all passed arguments into a string without using rest parameters, but with the help of the arguments object:
function strjoin(separator) {
var result = '';
for (var i = 1; i < arguments.length; i++) {
result += arguments[i];
if (i < arguments.length - 1) {
result += separator;
}
}
return result;
}
// Example usage:
console.log(strjoin(', ', 'apple', 'banana', 'cherry')); // "apple, banana, cherry"