Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can check this code and run it, i keep getting error screen shot for the result thank you needs_debugging.js const someSort = (array, compareFn =
can check this code and run it, i keep getting error screen shot for the result thank you 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started