使用 Underscore reduce() 时添加标点符号
Adding punctuation while using Underscore reduce()
这是我要回答的问题:
编写一个函数,接受一组名称并祝贺他们。确保使用 _.reduce 作为函数的一部分。
输入:['Steve'、'Sally'、'George'、'Gina']
输出:'Congratulations Steve, Sally, George, Gina!'
不知道最后那个感叹号怎么加!这是我的代码:
var names = ['Steve', 'Sally', 'George', 'Gina'];
var final = 'Congratulations ' + _.reduce(名称,函数(lastReduced,项目,索引,列表){
return lastReduced + ', ' + item + '!';
});
console.log(最终);
它输出:
"Congratulations Steve, Sally!, George!, Gina!" <=== 显然不正确!请帮忙。
var names = ['Steve', 'Sally', 'George', 'Gina'];
var final = 'Congratulations ' + _.reduce(names, function(lastReduced, item, index, list) { return lastReduced + ', ' + item;
});
final += '!';
console.log(final);
这是我要回答的问题:
编写一个函数,接受一组名称并祝贺他们。确保使用 _.reduce 作为函数的一部分。
输入:['Steve'、'Sally'、'George'、'Gina']
输出:'Congratulations Steve, Sally, George, Gina!'
不知道最后那个感叹号怎么加!这是我的代码:
var names = ['Steve', 'Sally', 'George', 'Gina'];
var final = 'Congratulations ' + _.reduce(名称,函数(lastReduced,项目,索引,列表){
return lastReduced + ', ' + item + '!';
});
console.log(最终);
它输出:
"Congratulations Steve, Sally!, George!, Gina!" <=== 显然不正确!请帮忙。
var names = ['Steve', 'Sally', 'George', 'Gina'];
var final = 'Congratulations ' + _.reduce(names, function(lastReduced, item, index, list) { return lastReduced + ', ' + item;
});
final += '!';
console.log(final);