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
interface Indexable { | |
[key: string]: any; | |
} | |
function isObject(val: any): boolean { | |
return Object.prototype.toString.call(val) === "[object Object]"; | |
} | |
function isObjectLike(val: any): boolean { | |
return val != null && typeof val === "object"; |
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
// https://monet.github.io/monet.js/ | |
import { Observable } from 'rxjs'; | |
import { Maybe } from 'monet'; | |
import { filter, map } from 'rxjs/operators'; | |
export function filterIsSome<T extends NonNullable<{}>>() { | |
return function (source: Observable<Maybe<T>>): Observable<Maybe<T>> { | |
return source.pipe(filter((maybe) => maybe.isSome())); | |
}; |
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
class Observable { | |
constructor(val) { | |
this._value = val; | |
this._listeners = []; | |
} | |
get value() { | |
return this._value; | |
} |
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 { | |
AfterContentInit, | |
ContentChildren, | |
Directive, | |
ElementRef, | |
Input, | |
QueryList, | |
Renderer2, | |
} from '@angular/core'; | |
import { startWith } from 'rxjs/operators'; |
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
@mixin flex($dir: row, $justify: start, $align: start, $wrap: wrap) { | |
display: flex; | |
@if $dir != row { | |
flex-direction: $dir; | |
} | |
@if $wrap != wrap { | |
flex-wrap: $wrap; | |
} | |
@if $justify != start { | |
justify-content: $justify; |
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
/* | |
Next greater element left or right | |
Next smaller element left or right | |
*/ | |
// [1, 3, 2, 4] => [-1, 1, 1, 2] | |
// [1, 3, 0, 0, 1, 2, 4] => [-1, 1, -1, -1, 0, 1, 2] | |
function nextSmallerLeft(nums) { | |
const ans = []; | |
const stack = []; |
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 ListNode(val, next) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.next = (next===undefined ? null : next) | |
* } | |
*/ | |
function length(head) { | |
if (head) { | |
let count = 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
/* | |
Ref: https://monet.github.io/monet.js/ | |
*/ | |
const { Some, None } = Monet; | |
function map(fn) { | |
return function (v) { | |
return Some(fn(v)); | |
} | |
} |
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
class Try { | |
constructor(val) { | |
this._val = val; | |
} | |
static of(fn) { | |
try { | |
return new Success(fn()); | |
} catch (err) { | |
return new Failure(err); |
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 BufferIterator(collection, bufferSize) { | |
this[Symbol.iterator] = function () { | |
let nextIndex = 0; | |
return { | |
next: () => { | |
if (nextIndex < collection.length) { | |
const buffer = new Array(bufferSize); | |
for (let i = 0; i < bufferSize; i++) { | |
buffer[i] = collection[nextIndex++]; |
NewerOlder