Skip to content

Instantly share code, notes, and snippets.

View thunder775's full-sized avatar
🎯
Focusing

Rahul Masih thunder775

🎯
Focusing
View GitHub Profile
function withoutRegExp(string = '') {
let queue = [];
let currentString = '';
for (let i = 0; i < string.length; i++) {
if (string.charAt(i) === '(') {
queue.push(currentString);
currentString = '';
} else if (string.charAt(i) === ')') {
currentString = queue.pop() + currentString.split('').reverse().join('');
} else {
1
A
D [-2]
[10,10,10,-20]
1
2
3
B
D [10,10,-20]
function asteroidCollision(asteroids) {
while (asteroids.length > 1) {
for (let i = 1; i < asteroids.length; i++) {
let [asteroidX, asteroidY] = [asteroids[i - 1], asteroids[i]];
while (asteroidX > 0 && asteroidY < 0&&i>=1) {
if (Math.abs(asteroidX) === Math.abs(asteroidY)) {
asteroids.splice(i - 1, 2)
} else if (Math.abs(asteroidX) < Math.abs(asteroidY)) {
asteroids.splice(i - 1, 1)
} else {
function asteroidCollision(asteroids) {
while (asteroids.length > 1) {
for (let i = 1; i < asteroids.length; i++) {
let [asteroidX, asteroidY] = [asteroids[i - 1], asteroids[i]];
while (asteroidX > 0 && asteroidY < 0&&i>=1) {
if (Math.abs(asteroidX) === Math.abs(asteroidY)) {
asteroids.splice(i - 1, 2)
} else if (Math.abs(asteroidX) < Math.abs(asteroidY)) {
asteroids.splice(i - 1, 1)
} else {
function boxShadows(rectangles = [[]]) {
rectangles.sort((a, b) => a[0] - b[0]);
// console.log(rectangles);
let linearMap = new Map();
for (let [x, y, width, height] of rectangles) {
let currentWidth = linearMap.get(x);
if (currentWidth === undefined) {
currentWidth = width + x
} else {
currentWidth = x + width > currentWidth ? width : currentWidth
function rotateImage(imageMatrix = [[]]) {
//transpose the matrix
for (let row = 0; row < imageMatrix.length; row++) {
for (let col = row + 1; col < imageMatrix[0].length; col++) {
let temp = imageMatrix[row][col];
imageMatrix[row][col] = imageMatrix[col][row];
imageMatrix[col][row] = temp;
}
}
// return each row reversed
function splitAndDelimit(string = '', interval = 1, delimiter = '') {
let iterator = 0;
for (let i = 0; i < string.length; i++) {
if (iterator === interval) {
string = string.substring(0, i) + delimiter + string.substring(i, string.length)
iterator = 0;
}else{
iterator++;}
}
console.log(string)
line A: 1, 2, 3, 1
line B: 2, 1, 2
(0,1){
(1,2){
}!(1,2){
}
}!(0,1){