Javascript Challenge Sort Array without Built In Step By Step

Javascript Challenge Sort Array without Built In Step By Step

amil hasbala

5 лет назад

12,836 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Maher Madany
Maher Madany - 25.09.2022 20:57

Excellent code, simple bug that can be fixed easily

Ответить
Lv10 Chiju
Lv10 Chiju - 25.08.2022 20:07

I dont care how you code but the output is not true

Ответить
shakeel ahmed
shakeel ahmed - 20.07.2022 18:00

Dont code 💩

Ответить
kushal davda
kushal davda - 20.03.2022 15:04

This doesn't sory negative numbers in an array

Ответить
shwetha hv
shwetha hv - 14.12.2021 21:23

Please dont confuse beginners, they might start hating to code

Ответить
shwetha hv
shwetha hv - 14.12.2021 21:22

Such a complex code , why cant you use two i and j loop
for (let i = 0; i < arr.length; i++) {
for (j = i + 1; j < arr.length; j++) {
if (arr[i] > arr[j]) {
temp = arr[j];
arr[j] = arr[i];
arr[i] = temp
}
}
}

Ответить
Erick Gonzalez
Erick Gonzalez - 13.09.2021 12:36

DIdn't know I could vibe to a js sort tutorial

Ответить
Aakash Chauhan
Aakash Chauhan - 10.12.2020 09:01

For better output use below code.

function Sort(array) {
var done = false;
while (!done) {
done = true;
for (var i = 1; i < array.length; i++) {
if (array[i - 1] > array[i]) {
done = false;
var tmp = array[i - 1];
array[i - 1] = array[i];
array[i] = tmp;
}
}
}

return array;
}

var numbers = [121,12, 10, 15,444, 11, 14, 13, 16,1];
Sort(numbers);
console.log(numbers);

Ответить
Aram 01
Aram 01 - 11.07.2020 21:48

let arr = [4, 3, 2, 1, 5, 8, 7, 2];
function arrSort(arrName) {
for (let i = 0, n = arrName.length; i < n; i++) {
for (let ii = 0; ii < n; ii++) {
if (arrName[i] < arrName[ii]) {
let arajin = arrName[i];
let verjin = arrName[ii];
arrName[i] = verjin;
arrName[ii] = arajin;
}else{
continue;
}
}
}
}
arrSort(arr);
console.log(arr);

Ответить
Ankit Jain
Ankit Jain - 16.04.2020 08:11

Seems like your final result is still not sorted . Is it ? [2,5,3,7,1....] ... how is this sorted ? And the reason for that is, you are putting your if swapped == 0 condition inside the for loop. You need to move that outside

Ответить