O
O
One of Us2018-10-29 08:52:25
JavaScript
One of Us, 2018-10-29 08:52:25

How to sort two arrays into one?

Hello!
There are two arrays, different lengths with unsorted numbers. How to sort them into one?
I want to write this function in js, but the example will work in any language. I just can’t imagine, and from the algorithms I know only the bubble method, but I don’t know how to apply it in this situation.
Please help, thanks in advance!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Rsa97, 2018-10-29
@Vlados102rus

.concat
.sort

A
Alexey, 2018-10-29
@Azperin

var arr = [1,2,3];
var arr2 = [4,5,6];
var arrSorted = [...arr, ...arr2].sort();

#
#, 2018-10-29
@mindtester

merge sort exists but in your case, it 's from a sparrow gun *
so as already said:
1 - merge
2 - sort
* - the algorithm is not suitable for arrays, but

a sorting algorithm that orders ... ... data structures whose elements can only be accessed sequentially, such as streams
but if this is exactly what they want from you in the educational process, use

Владимир Олохтонов, 2018-10-29
@sgjurano

Слить их, а затем отсортировать.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question