美文网首页
数组排序01

数组排序01

作者: 九瀺 | 来源:发表于2020-01-09 23:24 被阅读0次

    arr1 = ["A1", "A2", "B1", "C1", "D1"]
    arr2 = ["A", "B", "C", "D"]
    将arr1和arr2拼接成arr
    arr = ["A1","A2","A","B1","B","C1","C","D1","D"]

    let arr1 = ["A1", "A2", "B1", "C1", "D1"]
    let arr2 = ["A", "B", "C", "D"]
    let arr = []
            let c = 0
            for (let i = 0; i < arr2.length; i++) {
                for (let k = c; k < arr1.length; k++) {
                    if (arr1[k].startsWith(arr2[i])) {
                        arr.push(arr1[k])
                        c++
                    } else {
                        arr.push(arr2[i])                   
                        break
                    }
                }
            }
    

    相关文章

      网友评论

          本文标题:数组排序01

          本文链接:https://www.haomeiwen.com/subject/yowuactx.html