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
| 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
| [ | |
| { | |
| "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
| 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
| <?php | |
| /** | |
| * @package Ahamed\JsPhp | |
| * @author Sajeeb Ahamed <sajeeb07ahamed@gmail.com> | |
| * @copyright (c) Sajeeb Ahamed 2021 | |
| * @see https://github.com/ahamed/jsphp | |
| */ | |
| $book = [ | |
| 'id' => [1, 2, 3, 4, 5], | |
| 'title' => ['Master PHP', 'Python In Action', 'Advance engllish for learners', 'Maths for kids', 'Color theory'], |
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
| <?php | |
| /** | |
| * @package Ahamed\JsPhp | |
| * @author Sajeeb Ahamed <sajeeb07ahamed@gmail.com> | |
| * @copyright Copyright (c) 2021 Sajeeb Ahamed | |
| * @see https://github.com/ahamed/jsphp | |
| */ | |
| use Ahamed\JsPhp\JsArray; |
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
| /** | |
| * Get edge value of an array using user defined function. The edge value means either max or min value. | |
| * | |
| * @author Sajeeb Ahamed <sajeeb07ahamed@gmail.com> | |
| */ | |
| Array.prototype.findEdge = function(callback) { | |
| // If no value exists to the array then return undefined | |
| if (this.length === 0) return undefined; | |
| let edge = this[0]; |
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
| /** | |
| * Run Async function and get the result and the error without using try catch. | |
| * | |
| * @author Sajeeb Ahamed <sajeeb07ahamed@gmail.com> | |
| */ | |
| const runAsync = (func) => func.then((data) => [data, undefined]).catch((error) => Promise.resolve([undefined, error])); | |
| // A function which will return a promise and throw error | |
| const getData = () => { | |
| return new Promise((_, reject) => { |

