Question: The attached JavaScript program (needs_debugging.js) is intended for sorting an array. There are 5 errors in the program that needs to be fixed for the

The attached JavaScript program (needs_debugging.js) is intended for sorting an array. There are 5 errors in the program that needs to be fixed for the program to work correctly. 4 of the errors are syntax errors. One of the errors is a logical error. To debug the logical error, you need to understand how the program works. You may then use console.log() to print the contents of the bindings to find the bug. Submit the corrected working JavaScript file. In a text file, list all the bugs you fixed along with the original line numbers of the bugs.

needs_debugging.js

const someSort = (array, compareFn = defaultCompare) => { const { length } = array; let indexMin; for (let i = 0; i < length - 1, i++) { indexMin = i; for (let j = i; j < length; j++) if (compareFn(array[indexMin], array[j]) === Compare.BIGGER_THAN) { indexMin = i; } } if (i !== indexMin) { swap(array, i, indexMin); } } return array; };

function swap(array, a) { /* const temp = array[a]; array[a] = array[b]; array[b] = temp; */ [array[a], array[b]] = [array[b], array[a]]; }

const Compare = { LESS_THAN: -1, BIGGER_THAN: 1, EQUALS: 0 };

function defaultCompare(a, b) { if (a === b) { return Compare.EQUALS; } return a < b ? Compare.LESS_THAN : Compare.BIGGER_THAN; }

let array = [3,2,6,5,4,9,8,7,1]; array = samesort(array); console.log(array);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!