There is an unfinished sorting function, which should find the minimum element of the array and insert it into the new array. Since I donβt know how to remove the previous minimum element, the function returns an array from the minimal number itself from the given array (for example [44, 5, 2, 6, 3] it gives [2, 2, 2, 2, 2] , instead of [2, 3, 5, 6, 44] )
I need to add / correct the code below, not a new or abbreviated version. I want to understand how it works through functions and cycles, how many I have not tried in different ways - all in vain:
function sort(arr) { var sorted = []; var min = Infinity; for (j = 0; j < arr.length; j++) { for (var i = 0; i < arr.length; i++) { if (arr[i] < min ) { min = arr[i]; } } sorted.push(min); } return sorted; }
arr.splice(i, 1)- will remove the element - vp_arth