meibin08 / free-programming-books

📚码农周报 免费的编程书籍,leetcode(力扣)题解、前端算法题,牛客网前端大厂面试题题解、提升工作效率的常用工具等📈🎉
https://susouth.com/
424 stars 60 forks source link

Array-解题:两数组合并成指定格式 #29

Open meibin08 opened 5 years ago

meibin08 commented 5 years ago

请把两个数组 [A1, A2, B1, B2, C1, C2, D1, D2] 和 [A, B, C, D], 合并为 [A1, A2, A, B1, B2, B, C1, C2, C, D1, D2, D]

meibin08 commented 5 years ago
var arr = ["A1","A2", "B1", "B2", "C1", "C2", "D1", "D2"]  ;
["A", "B", "C", "D"].map((k,v)=>{
  arr.splice((1+v)*2 + v,0,k );
});