Answer the question
In order to leave comments, you need to log in
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
var arr = [1,2,3];
var arr2 = [4,5,6];
var arrSorted = [...arr, ...arr2].sort();
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 streamsbut if this is exactly what they want from you in the educational process, use
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question