Skip to content

Instantly share code, notes, and snippets.

@bengrunfeld
Last active July 26, 2020 13:54
Show Gist options
  • Save bengrunfeld/9f6c2fa03556f5ae4cf749f89291d5be to your computer and use it in GitHub Desktop.
Save bengrunfeld/9f6c2fa03556f5ae4cf749f89291d5be to your computer and use it in GitHub Desktop.
Toolbox of Useful Code
// Find the min of an array
const a = [3, 8, 2, 99, 1, 42, 23]
Math.min.apply(Math, a)
// How to turn an array into an object
const a = [3, 8, 2, 99, 1, 42, 23]
const b = a.reduce((a, b, i) => {
const obj = {}
obj[i] = b
return obj
}, {})
// Create a dynamic array and fill it with random numbers
[...Array(20).keys()].map(() => Math.floor(Math.random() * 100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment