Skip to content

Instantly share code, notes, and snippets.

View thunder775's full-sized avatar
🎯
Focusing

Rahul Masih thunder775

🎯
Focusing
View GitHub Profile
function taskScheduler(tasks = [], n = 1) {
let charMap = {};
tasks.forEach((task) => {
if (charMap[task] !== undefined) {
charMap[task] += 1
} else {
charMap[task] = 1;
}
});
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]);
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]);
function getAllPossiblePaths(paths = [[]], source, target) {
let result = [];
let connectingPaths = paths.filter(([s1, s2, dist]) => s1 === source || s2 === source).map(([s1, s2, dist]) => [source, s1 === source ? s2 : s1, dist]);
if (connectingPaths.length === 0) {
return [];
}
for (let [src, tgt, dist] of connectingPaths) {
paths = paths.filter(([s1, s2, target]) => !((s1 === src && s2 === tgt) || (s1 === tgt && s2 === src)));
if (tgt === target) {
result.push([[src, tgt, dist]])
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]));
call function navigate( A, T, [ AK, PT, AP, PQ, TQ, AT]){
let result = []
// tracking AK
call function navigate( K, T, [ PT, AP, PQ, TQ, AT]) {
let result = []
return result;
}
// tracking AP
call function navigate( P, T, [PT, PQ, TQ, AT]) {
class Pagination {
constructor(items = [], pageSize = 10) {
this.pagesArray = this.getPages(items, pageSize);
this.pointer = 0;
}
prevPage() {
if (this.pointer !== 0) {
this.pointer--;
return this;
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++;
}
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
});
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]) => {