1

Some time ago, I asked a question on Stack Overflow about sorting an array with JavaScript reduce function. And many kind users answer my question and I got some ideas about implementing a sorting algorithm with reduce function.

Actually, In my newest project, I have a big array that should be sort as fast as could happen ever. I implement some algorithms but I think I do not use JavaScript functions truly. I read some articles in medium and one of them is this article. I don't seek for a high-performance algorithm for sorting. Just like the article said, there is no fast way faster than nLog(n). I seek a real fast implementation in execution.

Is there a JavaScript built-in function for this or do you know an awesome sorting implementation for sorting big scale arrays?

12
  • How big is that array? Can you tell the approximate length of the array? Commented Oct 5, 2018 at 9:16
  • 1
    @AmmarHasan, The arrays sometimes have 100k about 500k items, but they are not alone, many of them should sort at the same time. Commented Oct 5, 2018 at 9:20
  • Are you mutating your array or creating a sorted copy? Commented Oct 5, 2018 at 9:20
  • 1
    Each time when you are creating a new copy of array it costs some memory and time to alloc it. So, mutating is faster one for sure. Commented Oct 5, 2018 at 9:23
  • 2
    Can you add some code example of array item? Commented Oct 5, 2018 at 9:23

1 Answer 1

0
   const array1 = [1, 30, 4, 21, 100000];
   array1.sort();
   array1.sort(function sortFunction() {...})

More info:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.