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
| /** | |
| * Merge two or more same structured arrays of objects | |
| * and make them unique by user provided keys. | |
| * | |
| * @author Sajeeb Ahamed | |
| */ | |
| const mergeArrays = (...arrays) => { | |
| // Consider the last argument as the keys | |
| const keys = arrays.pop(); |
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
| /** | |
| * Ways to convert a numeric string to a number. | |
| * | |
| * @author Sajeeb Ahamed | |
| */ | |
| const str = '343'; | |
| // Using parseInt method. | |
| number = parseInt(str); |
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
| /** | |
| * Check a number is odd or even. | |
| * | |
| * @author Sajeeb Ahamed | |
| */ | |
| let num = 234; | |
| /** Mod the number with 2 and if it returns 1 then odd, even otherwise */ | |
| if (num % 2) console.log('Odd'); | |
| else console.log('Even'); |
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
| /** | |
| * Create chunk using a fixed size. | |
| * | |
| * @author Sajeeb Ahamed | |
| * @see https://stackoverflow.com/a/61413202/4610740 | |
| */ | |
| // Add the chunk function into the array prototype. | |
| Array.prototype.chunk = function(size) { | |
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
| # Checkout to the reseting branch | |
| #e.g. `git checkout master` | |
| git checkout old_branch | |
| # reset hard by the new branch's contents | |
| # e.g. `git reset --hard origin/v2.0.0` | |
| git reset --hard new_branch | |
| # force push the contents to the origin |
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
| /** | |
| * The behavior of JavaScript sort method on integer array. | |
| * | |
| * @author Sajeeb Ahamed <sajeeb07ahamed@gmail.com> | |
| */ | |
| const arr = [3, 4, 2, 100, 98, 34]; | |
| arr.sort(); | |
| /** | |
| * Output: [100, 2, 3, 34, 4, 98] |
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) => { |
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
| <?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
| <?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'], |
OlderNewer