Last active
December 17, 2023 09:02
-
-
Save Deri-Kurniawan/59df1666d7e30cb2c8f3e9be0ae0dcd5 to your computer and use it in GitHub Desktop.
A collection of Javascript functions to remind us and that we might need
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
// Get a random number between 1 to max number | |
function randomNumber(max) { | |
return Math.floor(Math.random() * max); | |
} | |
// Get a random number between min and max number | |
function randomNumberInRange(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
// Sort number in array as ascending | |
function sortAsc(array) { | |
return array.sort((a, b) => a - b); | |
} | |
// Sort number in array as descending | |
function sortDesc(array) { | |
return array.sort((a, b) => b - a); | |
} | |
// Concat array to one array infinite | |
function concatArray(baseArray, ...nArray) { | |
return baseArray.concat(...nArray); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment