This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function taskScheduler(tasks = [], n = 1) { | |
let charMap = {}; | |
tasks.forEach((task) => { | |
if (charMap[task] !== undefined) { | |
charMap[task] += 1 | |
} else { | |
charMap[task] = 1; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function scheduler(array = [], n = 2) { | |
let taskCount = new Map(); | |
array.forEach((char) => { | |
if (taskCount.get(char) !== undefined) { | |
taskCount.set(char, taskCount.get(char) + 1) | |
} else { | |
taskCount.set(char, 1) | |
} | |
}); | |
let sortedFrequencies = [...taskCount.entries()].sort((a, b) => b[0] - a[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function scheduler(array = [], n = 2) { | |
let taskCount = new Map(); | |
array.forEach((char) => { | |
if (taskCount.get(char) !== undefined) { | |
taskCount.set(char, taskCount.get(char) + 1) | |
} else { | |
taskCount.set(char, 1) | |
} | |
}); | |
let sortedFrequencies = [...taskCount.entries()].sort((a, b) => b[1] - a[1]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tournamentScores(matchArray = ['', '']) { | |
let teamDataMap = new Map(); | |
matchArray.forEach((matchString) => { | |
let [team1, team2] = matchString.split(' - '); | |
let [team1Name,team1Goals] = team1.split(' '); | |
let [team2Name,team2Goals] = team1.split(' '); | |
addToMap(teamDataMap,team1Name,Number(team1Goals),Number(team2Goals)); | |
addToMap(teamDataMap,team2Name,Number(team2Goals),Number(team1Goals)); | |
}); | |
let result = [...teamDataMap.entries()].map(array => Array.from([array[0]]).concat(array[1])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pagination { | |
constructor(items = [], pageSize = 10) { | |
this.pagesArray = this.getPages(items, pageSize); | |
this.pointer = 0; | |
} | |
prevPage() { | |
if (this.pointer !== 0) { | |
this.pointer--; | |
return this; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function interprime(num = 0) { | |
if (num === 0 || isPrime(num)) return []; | |
let prevPrime = num - 1; | |
while (!isPrime(prevPrime) && prevPrime > 0) { | |
prevPrime--; | |
} | |
let nextPrime = num + 1; | |
while (!isPrime(nextPrime)) { | |
nextPrime++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
res.sort(([teamAName,teamAPoints,teamAGoals,teamAGD],[teamBName,teamBPoints,teamBGoals,teamBGD])=>{ | |
if(teamAPoints!==teamBPoints) return teamBPoints-teamAPoints; | |
else if(teamAGoals!==teamBGoals) return teamBGoals-teamAGoals; | |
else return teamBGD-teamAGD | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tournamentScores(matchArray = ['', '']) { | |
let teamDataMap = new Map(); | |
matchArray.forEach((matchString) => { | |
let [team1, team2] = matchString.split(' - '); | |
let [team1Name, team2Name] = [team1.split(' ')[0], team2.split(' ')[1]]; | |
let [team1Goals, team2Goals] = [Number(team1.split(' ')[1]), Number(team2.split(' ')[0])]; | |
addToMap(teamDataMap, team1Name, team1Goals, team2Goals); | |
addToMap(teamDataMap, team2Name, team2Goals, team1Goals); | |
}); | |
return Array.from(teamDataMap.entries()).sort(([teamA, statsA], [teamB, statsB]) => { |