* fix: Replace Array.prototype.sort and update old isSorted method. * fix: Change name of function from 'checkInBuiltSort' to 'checkBuilitInSort'. * fix: Change name of function from 'checkBuilitInSort' to 'isBuiltInSortUsed'.
4.0 KiB
4.0 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d825b367417b2b2512c8c | Implement Heap Sort with a Min Heap | 1 | Implementar Heap Sort con un Min Heap |
Description
Instructions
Tests
tests:
- text: La estructura de datos MinHeap existe.
testString: 'assert((function() { var test = false; if (typeof MinHeap !== "undefined") { test = new MinHeap() }; return (typeof test == "object")})(), "The MinHeap data structure exists.");'
- text: MinHeap tiene un método llamado insertar.
testString: 'assert((function() { var test = false; if (typeof MinHeap !== "undefined") { test = new MinHeap() } else { return false; }; return (typeof test.insert == "function")})(), "MinHeap has a method called insert.");'
- text: MinHeap tiene un método llamado eliminar.
testString: 'assert((function() { var test = false; if (typeof MinHeap !== "undefined") { test = new MinHeap() } else { return false; }; return (typeof test.remove == "function")})(), "MinHeap has a method called remove.");'
- text: MinHeap tiene un método llamado ordenar.
testString: 'assert((function() { var test = false; if (typeof MinHeap !== "undefined") { test = new MinHeap() } else { return false; }; return (typeof test.sort == "function")})(), "MinHeap has a method called sort.");'
- text: El método de clasificación devuelve una matriz que contiene todos los elementos agregados al montón mínimo en orden ordenado.
testString: 'assert((function() { var test = false; if (typeof MinHeap !== "undefined") { test = new MinHeap() } else { return false; }; test.insert(3); test.insert(12); test.insert(5); test.insert(10); test.insert(1); test.insert(27); test.insert(42); test.insert(57); test.insert(5); var result = test.sort(); return (isSorted(result)); })(), "The sort method returns an array containing all items added to the min heap in sorted order.");'
Challenge Seed
// check if array is sorted
function isSorted(a){
for(let i = 0; i < a.length - 1; i++)
if(a[i] > a[i + 1])
return false;
return true;
}
// generate a randomly filled array
var array = new Array();
(function createArray(size = 5) {
array.push(+(Math.random() * 100).toFixed(0));
return (size > 1) ? createArray(size - 1) : undefined;
})(25);
var MinHeap = function() {
// change code below this line
// change code above this line
};
Solution
// solution required