Last active
March 17, 2022 10:44
-
-
Save hsoulier/fbedf81b2d4bed94c10747e965c34afc to your computer and use it in GitHub Desktop.
Cheatsheet Typescript
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
const isArrayEmpty = (arr: unknown[]): boolean => Array.isArray(arr) && !arr.length; | |
const capitalize = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1); | |
const isObjectEmpty = (obj: unknown): boolean => obj && Object.keys(obj).length === 0; | |
const randomInteger = (min: number, max: number): number => Math.floor(Math.random() * (max - min + 1)) + min; | |
const clamp = (input: number, min: number, max: number): number => input < min ? min : input > max ? max : input | |
const map = (current: number, in_min: number, in_max: number, out_min: number, out_max: number): number => { | |
const mapped: number = ((current - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min; | |
return clamp(mapped, out_min, out_max); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment