Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AwesomeDevin opened this issue Sep 18, 2023 · 0 comments
Open

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

AwesomeDevin opened this issue Sep 18, 2023 · 0 comments

Comments

@AwesomeDevin
Copy link
Owner

  • 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)
  • 归并排序
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant