Skip to content

Instantly share code, notes, and snippets.

@alekstar79
Created February 4, 2023 07:59
Show Gist options
  • Save alekstar79/b0f07ac7ea7a362da8cf77018960d43a to your computer and use it in GitHub Desktop.
Save alekstar79/b0f07ac7ea7a362da8cf77018960d43a to your computer and use it in GitHub Desktop.
One-line JavaScript functions
// 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