Skip to content

Instantly share code, notes, and snippets.

@Deri-Kurniawan
Last active December 17, 2023 09:02
Show Gist options
  • Save Deri-Kurniawan/59df1666d7e30cb2c8f3e9be0ae0dcd5 to your computer and use it in GitHub Desktop.
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
// 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