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 range = (min, max) => { | |
| // If max value is smaller than the min value then swap it. | |
| if (max < min) [min, max] = [max, min]; | |
| const _range = (max + 1) - min; | |
| return Array.from({length: _range}, (_, i) => min + i); | |
| } | |
| console.log(range(1, 5)); // 1, 2, 3, 4, 5 | |
| console.log(range(10, 5)); // 5, 6, 7, 8, 9, 10 |
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
| [ | |
| { | |
| "id": 1, | |
| "name": "Putin FM", | |
| "frequency": "66,6", | |
| "image": "./assets/images/stations.planet-01.jpeg" | |
| }, | |
| { | |
| "id": 2, | |
| "name": "Dribble FM", |
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 Node(character) { | |
| this.value = character; | |
| this.endOfWord = false; | |
| this.children = {}; | |
| } | |
| class Trie { | |
| constructor() { | |
| this.root = new Node(null); | |
| } |
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
| /** | |
| * Find a year is a leap year or not. | |
| * The logic is simple, create an instance of a date | |
| * with the date 29 of the february of the given year. | |
| * If the date 29 exists in that year that means the | |
| * year is a leap year, otherwise it's not. | |
| * What a brilliant idea. | |
| * | |
| * @author 📩 Sajeeb Ahamed <sajeeb07ahamed@gmail.com> |
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 arr1 = [1, 2, 3, 4, 6, 5, 2]; | |
| const arr2 = [2, 3, 1, 4, 2, 5, 6]; | |
| const isSameArray = (arr1, arr2) => { | |
| if (arr1.length !== arr2.length) { | |
| return false; | |
| } | |
| // Create object like {1: 1, 2: 2, 3: 1 ...} , the number of frequency of an element in the array. |
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 const extractPromise = async < | |
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| F extends (...args: any) => Promise<any>, | |
| A extends Parameters<F>, | |
| R extends ReturnType<F>, | |
| >( | |
| promiseFn: F, | |
| ...args: A | |
| ): Promise<[Awaited<R> | undefined, unknown | undefined]> => { | |
| try { |
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
| type IncrementByOne<N extends number, T extends unknown[] = []> = | |
| T['length'] extends N | |
| ? [...T, unknown]['length'] | |
| : IncrementByOne<N, [...T, unknown]>; | |
| type IndexOf<T extends unknown[], U extends unknown, I extends number = 0> = | |
| I extends T['length'] | |
| ? -1 | |
| : T[I] extends U | |
| ? I |
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
| /** | |
| * Remove some properties from an object, | |
| * and work with other properties. | |
| * | |
| * You can use destructuring and ...rest operator for gaining this result. | |
| * | |
| * @author Sajeeb Ahamed <sajeeb07ahamed@gmail.com> | |
| */ | |
| const store = { | |
| id: '123', |

