AwesomeDevin / blog

Welcome to Devin's blog,I'm trying to be a fullstack developer and sticking with it !!!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

合并二维有序数组成一维有序数组

AwesomeDevin opened this issue · comments

  • concat + reduce + sort
const arr1 = [[1,2,3,7,9],[1,3,4,6,7,8]]
const arr2 = [[2,5],[4,10]]

function merge(arr1, arr2){
   return arr1.concat(arr2).reduce((x,y)=>x.concat(y),[]).sort((x,y)=>x>y?1: -1)
}

merge(arr1,arr2)
  • 归并排序