Union types. They enable cool things and can eliminate an entire class of bugs that would only otherwise be discovered at runtime.
They look like this:
type Key = string | number | symbol;| import { Observable, Subscriber } from 'rxjs'; | |
| type Dictionary<T> = { | |
| [key: string]: T; | |
| }; | |
| export type AddedEvent<T> = { | |
| type: 'added'; | |
| value: T; | |
| }; |
| import { Observable, Subscriber } from 'rxjs'; | |
| const nextCss = `background-color: cyan; color: #000000; font-weight: bold;`; | |
| const errorCss = `background-color: #f64040; color: #ffffff; font-weight: bold;`; | |
| const completeCss = `background-color: rgb(24, 255, 148); color: #000000; font-weight: bold;`; | |
| export const tag = (tagText: string, stringify = false) => { | |
| return <T>(source: Observable<T>) => | |
| new Observable((observer: Subscriber<T>) => { | |
| let count = 0; |
| import { curry } from 'ramda'; | |
| export const range = (from: number, to: number) => { | |
| const result = []; | |
| let n = from - 1; | |
| while (++n < to) result.push(n); | |
| return result; | |
| }; | |
| export const clamp = curry((min: number, max: number, value: number) => { |
| import { Observable, Subject } from 'rxjs'; | |
| import { takeUntil } from 'rxjs/operators'; | |
| export const untilDestroyed = <C extends any>( | |
| componentInstance: C, | |
| destroyMethodName = 'ngOnDestroy' | |
| ) => <T>(source: Observable<T>) => { | |
| const originalDestroy = componentInstance[destroyMethodName]; | |
| if (typeof originalDestroy !== 'function') { | |
| throw new Error( |
data) as an array of items (item)keygen): A pure function that, given an item from data, returns a deterministic key as a string.tokenizer): A pure function that, given an item from data, returns a list of tokens (strings) describing that item.These are the JS Array methods that should be your go-to tools for everything. They're the building blocks of some extremely powerful combinations of algorithmic logic.
The problems below all require that you write a function that performs a simple data transformation on a generic, opaque set of data.
Note that many functions are variadic by way of the rest operator. If you're not sure what this means, read this.
These are the rules:
| --- | |
| Language: Cpp | |
| BasedOnStyle: Mozilla | |
| AccessModifierOffset: -2 | |
| AlignAfterOpenBracket: AlwaysBreak | |
| AlignConsecutiveAssignments: true | |
| AlignConsecutiveDeclarations: false | |
| AlignEscapedNewlines: Left | |
| AlignTrailingComments: true | |
| AlignOperands: true |