Skip to content

Instantly share code, notes, and snippets.

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);
};
let minClipNeeded = (clips, time) => {
clips.sort((a, b) => {
if (a[0] === b[0]) {
return b[1] - a[1];
}
else {
return a[0] - b[0];
}
});
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);
@AsifITk
AsifITk / d45
Created September 9, 2022 04:57
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}`)
}
}
}
@AsifITk
AsifITk / day44
Last active September 9, 2022 04:55
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 {
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,});
@AsifITk
AsifITk / d41
Created September 8, 2022 21:12
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) {
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) {
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}`)
}
}
}
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];
}