Created
October 13, 2022 02:34
-
-
Save buymed-hoangpham/af13b98de6084dc3bae35f1d3c8f7b2d to your computer and use it in GitHub Desktop.
lodash
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 _ = { | |
| clamp(number, lower, upper) { | |
| const lowerClampedValue = Math.max(number, lower); | |
| const clampedValue = Math.min(lowerClampedValue, upper); | |
| return clampedValue; | |
| }, | |
| inRange(number, start, end) { | |
| if (!end) { | |
| end = start; | |
| start = 0; | |
| } | |
| return number >= start && number <= end; | |
| }, | |
| words(string) {}, | |
| pad(string, length) {}, | |
| has(object, key) {}, | |
| invert(object) {}, | |
| findKey(object, predicate) { | |
| for (let key in object) { | |
| let value = object[key]; | |
| let predicateReturnValue = predicate(value); | |
| if (predicateReturnValue) { | |
| return key; | |
| } | |
| } | |
| }, | |
| drop(array, n) { | |
| return array.slice(n); | |
| }, | |
| dropWhile(array, predicate) { | |
| let idx = 0; | |
| while (predicate(array[idx], idx)) { | |
| idx += 1; | |
| } | |
| return array.slice(n); | |
| }, | |
| chunk(array, size) { | |
| let arrayChunks = []; | |
| for (let i = 0; i < array.length; i += size) { | |
| let arrayChunk = array.slice(i, i + size); | |
| arrayChunks.push(arrayChunk); | |
| } | |
| return arrayChunks; | |
| }, | |
| }; | |
| // Do not write or modify code below this line. | |
| module.exports = _; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment