Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function galactic(arr) {
- let galacticMap = new Map();
- for (let obj of arr) {
- let system = obj.system; let candidate = obj.candidate; let votes = Number(obj.votes);
- if(!galacticMap.has(system)){
- galacticMap.set(system,new Map());
- }
- if (!galacticMap.get(system).has(candidate)) {
- galacticMap.get(system).set(candidate, 0);
- }
- let oldValue = galacticMap.get(system).get(candidate);
- galacticMap.get(system).set(candidate,oldValue + votes);
- }
- let sorted = [...galacticMap].sort(mySort);
- //Тука пробвам с value и не става, а ако е value() със скобите гърми...
- function mySort(a,b) {
- return b[1].value - a[1].value;
- }
- //Тука и с мапа
- function mySort(a,b) {
- return galacticMap.get(b[1]) - galacticMap.get(a[1]);
- }
- //И така пробвах и пак не става
- let sorted = [...galacticMap].sort((a,b) => otherSort(galacticMap,a,b));
- function otherSort(map,a,b) {
- return map.get(b[1]) - map.get(a[1]);
- }
- //И така ъпсурт
- let sorted = [...galacticMap].sort(anotherSort);
- function anotherSort(a,b) {
- return b[1][1] - a[1][1];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement