Js array, deduplicated and filtered by category and sorted by numeric size

output array de-reordering filter

/ / Code to be implemented
/ / 1. If the id is duplicated, remove an item with a low level value
/ / 2. Items whose attribute acitive is true are at the top of the list
/ / 3. When the attribute acitive is the same, the level is higher
/ / 4. Returns a string of name-rating format
/ / return.

sources of topics and their own ideas

my idea is to use ForEach to repeat how to use filter filtering. Then will not, just entered the js to give me a big stew to ask the great god to analyze!

related codes

/ / the following are topics with their own conditions
const Stacks = [{

 id: 1,
 name: "JavaScript",
 level: 1,
 active: true
 },{
 id: 2,
 name: "CSS",
 level: 3,
 active: false
 },{
 id: 3,
 name: "HTML",
 level: 2,
 active: true
 },{
 id: 1,
 name: "JavaScript",
 level: 4,
 active: true
 },{
 id: 4,
 name: "JQuery",
 level: 1,
 active: false

}]
function output2 (Arr) {
}
output2 (Stacks);
/ / the result returns
/ / ["JavaScript-4","HTML-2","CSS-3","JQuery-1"];

what result do you expect? What is the error message actually seen?

Dec.28,2021

let result = Stacks
  .filter(a => !Stacks.some(b => a !== b && a.id === b.id && b.level > a.level))
  .sort((a, b) => a.active > b.active ? -1 : (a.active < b.active ? 1 : b.level - a.level))
  .map(a => `${a.name}-${a.level}`);

console.log(result);

function merge(arr){
 var cache=[],newArr=[];
 for(var i=0;i<arr.length;iPP){ //
   var id = arr[i].id,
       idx = cache.indexOf(id);
   idx==-1?(cache.push(id),newArr.push(arr[i])):
    (newArr[idx].level<arr[i].level&&(newArr.splice(idx,1),newArr.push(arr[i])));
 }
 return newArr.sort(function(a,b){ //
   return a.active?-1:(a.level>b.level?-1:1)
 });
}
merge(Stacks);

Stacks.sort((a,b)=>{
    if(a.active>b.active){
        return -1
    }else if(a.active==b.active){
        return b.level-a.level
    }else{
        return 1
    }
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea109c-1b23.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea109c-1b23.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?