我尝试了split()来创建一个数组,然后使用map()在字符串旁边添加数字。
function nameLength(str) {
const words = str.split(" ");
return words.map(str => $(words) $(words.length));
}
console.log(nameLength("hawaii pizza"));
was expecting:
[ 'hawaii 6', 'pizza 5' ]
我尝试了split()来创建一个数组,然后使用map()在字符串旁边添加数字。
function nameLength(str) {
const words = str.split(" ");
return words.map(str => $(words) $(words.length));
}
console.log(nameLength("hawaii pizza"));
was expecting:
[ 'hawaii 6', 'pizza 5' ]
1条答案
按热度按时间kognpnkq1#
你返回了错误的字符串.你的语法也是错误的,试试这个