编写一个名为combineThings的函数。这个功能应该:
创建并返回所有输入的新数组作为字符串 每个新字符串应以&#34开头; [index]为[data]"
例如:
combiningThings([1, 2, 3]) // returns ["0 is 1", "1 is 2", "2 is 3"]
combiningThings(['My', 1, 'number']) // returns ["0 is My", "1 is 1", "2 is number"]
var indexToString = function(arrayTwo) {
var combine = "";
for (var i = 0; i < arrayTwo.length; i++) {
combine += arrayTwo.indexOf(i++) + " is " + arrayTwo[i++];
}
return combine;
};
答案 0 :(得分:1)
这适用于地图:
function combiningThings(arr) {
return arr.map((v, index) => index + ' is ' + v);
}
console.log(combiningThings([1, 2, 3]));
console.log(combiningThings(['My', 1, 'number']));
答案 1 :(得分:0)
这应该有效:
function combiningThings(array) {
return array.map((el, index) => {
return index + ' is ' + el;
});
}
combiningThings(['My', 1, 'number']);
// This will give --> [ '0 is My', '1 is 1', '2 is number' ]