Created
February 4, 2023 07:59
-
-
Save alekstar79/b0f07ac7ea7a362da8cf77018960d43a to your computer and use it in GitHub Desktop.
One-line JavaScript functions
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
// Immutable Shuffle | |
const shuffleImmutable = (arr) => arr.slice().sort(() => Math.random() - 0.5) | |
// Random number in range | |
const randomInRange = (from, to) => Math.floor(from + Math.random() * (to - from + 1)) | |
// Array with unique items | |
const uniqueItems = (arr) => [...new Set(arr)] | |
// Uppercase firs letter | |
const ucfirst = (str) => str.charAt(0).toUpperCase() + str.slice(1) | |
// Unique ID | |
const uniqueID = () => Math.random().toString(36).slice(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment