N
N
nekmgf2015-11-10 09:36:26
JavaScript
nekmgf, 2015-11-10 09:36:26

How to create an array of 10000 random elements and sort it?

You need to create an array with 10,000 elements, sort using the bubble method and quick sort. Here is my bubble code:

var sort_lesson = {
  sortBubble : function( input array ){
    if(input_array.length < 1){ return false };
    var tmp;
    for (var i = input_array.length - 1; i > 0; i--) {
      for (var j = 0; j < i; j++) {
        if ( input_array[j] > input_array[j+1]) {
        	tmp = input_array[j];
        	input_array[j] = input_array[j+1]);
        input_array[j+1]=tmp;
        }
      }
    }
    return( input_array );
  }

  generateRandomArray : function(array_size ){
    array_size= Math.floor( array_size );
    if(array_size < 1){
      return false;
    }
  }
};


var array = sort_lesson.generateRandomArray( 10000 );
array=sort_lesson.sortBubble(array);
array.map( function(elem ){
  document.write(elem+'<br>');
});

But it does not work, because there are amendments that I do not quite understand and have added something incorrectly. It would be nice if there was an explanation of how this is done at all or some material related to this question. I just don't know how to create an array with 10,000 random elements.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
AlikDex, 2015-11-10
@AlikDex

habrahabr.ru/post/221807
www.sorting-algorithms.com
Forget about bubble sorting already.

S
svarnoi420, 2015-11-10
@inomdzhon92

Given that you wrote that you are not competent in programming, there is no point in writing about it, but the typos are:
I advise you to find a person who will personally explain the code to you face to face and help with random filling of the array.
And study programming :) purely for yourself, for example.

Y
Yaroslav Lyzlov, 2015-11-10
@dixoNich

Take and create. In my opinion, the problem here is not in JS, but simply not in understanding the very basics of programming, such as the same loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question