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
let avgWaitTime = function (customers) { | |
let total = 0; | |
let end = 0; | |
for (let i = 0; i < customers.length; i++) { | |
end = Math.max(end + customers[i][1], customers[i][0] + customers[i][1]); | |
total += end - customers[i][0]; | |
} | |
return (total / customers.length).toFixed(5); | |
}; |
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
let minClipNeeded = (clips, time) => { | |
clips.sort((a, b) => { | |
if (a[0] === b[0]) { | |
return b[1] - a[1]; | |
} | |
else { | |
return a[0] - b[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
let calcScore = (arr, guess) => { | |
let len = arr.length; | |
let count = 0; | |
let corr = 0; | |
let inc = 0; | |
for (let i = 0; i < arr.length; i++) { | |
if (arr[i] == guess[i]) { | |
corr++; | |
// arr.splice(i, 1); | |
// guess.splice(i, 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
let simplified = (num) => { | |
let final = []; | |
for (let i = 1; i < num; i++) { | |
for (let j = i + 1; j <= num; j++) { | |
if (gcd(j, i) === 1) { | |
final.push(`${i}/${j}`) | |
} | |
} | |
} |
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
let ifAliceWon = (stone) => { | |
let res = []; | |
while (stone != 0) { | |
let suqare = []; | |
for (let i = 1; i <= stone; i++) { | |
let tem = i * i; | |
if (tem > stone) { | |
break; | |
} else { |
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
1.db.restaurants.find(); | |
2.db.restaurants.find({},{"restaurant_id" : 1,"name":1,"borough":1,"cuisine" :1}); | |
3.db.restaurants.find({},{"restaurant_id" : 1,"name":1,"borough":1,"cuisine" :1,"_id":0}); | |
4. db.restaurants.find({},{address:{zipcode:1},_id:0}) | |
5.db.restaurants.find({},{borough:'Brooklyn',name:1}).skip(5).limit(5-10) | |
8. db.restaurants.find({'grades.score':{$gt: 70}}).count() | |
9.db.restaurants.find({grades:{$elemMatch:{score:{$lt:100,$gt:70}}}}).count() | |
10. {cuisine:{$ne:"American "},"grades.grade":"A",borough:{$ne:"Brooklyn"}} | |
11. {$and:[{cuisine:{$ne:"American "}},{cuisine:{$ne:"Chinese"}},{name:/^[^Sea]/}]} | |
12.sort({"cuisine":1,"borough" : -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
let whereTheBall = (grid) => { | |
let tempArr = []; | |
for (let i = 0; i < grid[0].length; i++) { | |
let ball = i; | |
tempArr.push(-1); | |
for (let j = 0; j < grid.length; j++) { | |
if (grid[j][ball] === 1 && grid[j][ball + 1] === 1) { ball = ball + 1; } | |
else if (grid[j][ball] === -1 && grid[j][ball - 1] === -1) { ball = ball - 1; } | |
else break; | |
if (j === grid.length - 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
let winner = (arr, k) => { | |
if (k >= arr.length) { | |
return Math.max(...arr); | |
} | |
let tem = {}; | |
let num1 = arr[0]; | |
let num2 = undefined; | |
for (let i = 1; i < arr.length; i++) { | |
num2 = arr[i]; | |
if (num1 > num2) { |
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
let simplified = (num) => { | |
let final = []; | |
for (let i = 1; i < num; i++) { | |
for (let j = i + 1; j <= num; j++) { | |
if (gcd(j, i) === 1) { | |
final.push(`${i}/${j}`) | |
} | |
} | |
} |
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 nBonacciRatio(n) { | |
function fib(x, tem = [0, 1, 1]) { | |
if (tem[x]) { | |
return tem[x]; | |
} | |
tem[x] = n * fib(x - 1, tem) + fib(x - 2, tem); | |
return tem[x]; | |
} |
NewerOlder