function scoreSorter(array, topScore) {
for (let i=0; i<array.length; i++) {
for (let j=0; j<array.length; j++){
if (array[i] > array[j]) {
[array[i], array[j]] = [array[j], array[i]];
}
}
}
return array;
}
console.log(scoreSorter([1, 2, 3, 9999, 13], 10000))
// Leave this so we can test your code:
module.exports = scoreSorter;
function scoreSorter(array, topScore) {
// Write your code here
let sortedArray = []
// let decimal = []
for(let j = 0; j < array.length; j++){
if(array[j] > topScore || array[j] < 0){
return "ERROR: not valid score"
}
// this accounts for multiples of number(not sure why/how it has to go first)
if (sortedArray.includes(array[j])){
sortedArray.splice(array[j],0,array[j])
}
sortedArray[array[j]] = array[j]
// this accounts for nonintegers
if(!Number.isInteger(array[j]) ){
sortedArray.splice(Math.floor(array[j]),0,array[j])
}
}
// this filters out underfined elements and reverses array
return sortedArray.filter(num => typeof num != undefined).reverse()
}
console.log(scoreSorter([1, 2,11111, 3, 9999, 13], 10000))
// Leave this so we can test your code:
module.exports = scoreSorter;
function scoreSorter(array, topScore) {
// Write your code here
let swapping = true;
let newArray=topScore ? array.filter(item=>item<=topScore):array;
while(swapping){
swapping=false;
for(let i = 0; i < newArray.length-1; i++){
if(newArray[i] < newArray[i+1]){
const temp=newArray[i];
newArray[i]=newArray[i + 1];
newArray[i+1]=temp;
swapping=true;
}
}
}
return newArray;
}
console.log(scoreSorter([13, 4, 9, 9999, 1],10000))
// Leave this so we can test your code:
module.exports = scoreSorter;
function quickSort(arr){
if(arr.length <= 1){
return arr;
}
const pivot = arr[arr.length - 1];
const leftArr = [];
const rightArr = [];
for(let i=0; i < arr.length-1;i++){
if(arr[i] < pivot){
leftArr.push(arr[i]);
}
else{
rightArr.push(arr[i])
}
}
return [...quickSort(leftArr) ,pivot,...quickSort(rightArr)];
}
function scoreSorter(array, topScore) {
return quickSort(array).reverse();
}
console.log(scoreSorter([1, 2, 3, 9999, 13], 10000))
// Leave this so we can test your code:
module.exports = scoreSorter;