在数组 arr 的 index 处添加元素 item。不要直接修改数组 arr,结果返回新的数组

添加元素

https://www.nowcoder.com/practice/941bcfa5b87940869fda681c1597fd3a?tpId=6&tqId=10958&tPage=1&rp=1&ru=/ta/js-assessment&qru=/ta/js-assessment/question-ranking

function insert(arr, item, index) {

var temp = arr.slice(0);
temp.splice(index,0,item);
return temp;

/*
var temp = [],res = [];
temp.push(arr.slice(0,index));
res.push(arr.slice(index));
temp.push(item);
return temp.concat(res);
*/

}

全部评论

相关推荐

ros275229:社团删了吧,cf因该1200才勉强入门吧,也删了,你可以写算法刷了多少道,都比这个好
点赞 评论 收藏
分享
01-19 12:48
门头沟学院 C++
只想搞钱的鸽子很喜欢...:混账是很多的,还有那些在自己风华正茂的年纪说风凉话讥讽那些下岗前员工的。这些人都是现在职场环境这么烂的帮凶
点赞 评论 收藏
分享
评论
7
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务