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 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 { |
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 | |
A | |
D,[-2] |
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 | |
A | |
D [-2] |
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
[10,10,10,-20] | |
1 | |
2 | |
3 | |
B | |
D [10,10,-20] |
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 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 { |
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 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 { |
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 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 |
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 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 |
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 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) |
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
line A: 1, 2, 3, 1 | |
line B: 2, 1, 2 | |
(0,1){ | |
(1,2){ | |
}!(1,2){ | |
} | |
}!(0,1){ |