This file contains hidden or 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
// leetcode answer for https://leetcode.com/problems/flood-fill/ | |
/** | |
* @param {number[][]} image | |
* @param {number} sr | |
* @param {number} sc | |
* @param {number} newColor | |
* @return {number[][]} | |
*/ | |
var floodFill = function(image, sr, sc, newColor) { |
This file contains hidden or 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
// it is fairly common in web land to need to get some data from a server, then do something else async with that data | |
// this is accomplished with the switchMap operator | |
// the switchMap operator takes a function that returns another observable. | |
// it then subscribes (or 'switches') to the returned observable | |
this.http.get(uri) | |
.pipe( | |
switchMap(response => { | |
const data = doSomething(response); |
This file contains hidden or 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
const a = [1, [2, 3], [[4, 5]]]; | |
function flatten(arr) { | |
if(!Array.isArray(arr)) { | |
return [arr]; | |
} | |
return arr.reduce((accumulator, current) => | |
[...accumulator, ...(flatten(current))], []); | |
} |
This file contains hidden or 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 asyncSetInterval(f: any, condition: () => boolean, delay: number) { | |
return new Promise(((resolve, reject) => { | |
const id = setInterval(() => { | |
f(); | |
if (condition()) { | |
resolve(); | |
clearInterval(id); | |
} | |
}, delay); | |
} |
This file contains hidden or 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
import { swapArrayIndexes, indexOfFirstOccurrence, indexOfLastOccurrence } from 'ArrayHelpers'; | |
function bits(numbers) { | |
return numbers.map(n => maximizeBinaryNumber(n)); | |
} | |
function maximizeBinaryNumber(number) { | |
const binaryValue = Number(number).toString(2).split(''); | |
const firstZero = indexOfFirstOccurence(binaryValue, 0); | |
const lastOne = indexOfLastOccurence(binaryValue, 1); |
This file contains hidden or 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
// original function | |
function bruh() { | |
if( x !== 1) doSomething(); | |
} | |
// obfuscated function results in something like this | |
function bruh(){if(x!==1)doSomething()} | |
// note the lack of white space in the if check. this will be relevant soon | |
This file contains hidden or 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
export class WindowResizeListener extends Component { | |
state = { | |
height: window.innerHeight, | |
width: window.innerWidth | |
} | |
componentDidMount() { | |
Observable.fromEvent(window, 'resize') | |
.debounceTime(250) |
This file contains hidden or 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
/** | |
* @param {string} s | |
* @return {boolean} | |
*/ | |
var isValid = function(s) { | |
var openingStack = []; | |
var closingStack = []; | |
var openingPair = ['(', '{', '[']; | |
var closingPair = [')', '}', ']']; | |
This file contains hidden or 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
/** | |
* Definition for singly-linked list. | |
* function ListNode(val) { | |
* this.val = val; | |
* this.next = null; | |
* } | |
*/ | |
/** | |
* @param {ListNode} head | |
* @param {number} n |
This file contains hidden or 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
/** | |
* @param {number[]} nums | |
* @return {number} | |
*/ | |
var maxSubArray = function(nums) { | |
var maximumSum = -Infinity; | |
nums.forEach((num, index) => { | |
var accumulator = num; | |
if(accumulator > maximumSum) maximumSum = accumulator; |
NewerOlder