Skip to content

Instantly share code, notes, and snippets.

@mi-mina
Created April 8, 2019 10:35
Show Gist options
  • Select an option

  • Save mi-mina/02101a4615eb9c652e915c0991f11c51 to your computer and use it in GitHub Desktop.

Select an option

Save mi-mina/02101a4615eb9c652e915c0991f11c51 to your computer and use it in GitHub Desktop.
// Remove any duplicates from an array of primitives.
const unique = [...new Set(arr)];
// Returns all non-falsy values from an array
[...].filter(Boolean);
// Just plain english
[...].every(Number.isFinite);
// Array destructuring to see matching elements
let [r, g, b, a] = [255, 0, 0, 255];
// Object destructuring to reduce multiple lines of code to a single one
let {widt, height} = resolution;
// Gets an item from the list and wraps around to the start if n is larger than the list.
items[n % items.length];
// Console.log in array function without adding curly braces
// Espe: don't understand what this is for
const addFortyTwo = number => console.log(number) || number + 42;
// Same as above
const add42 = n => (console.log(n), n + 42);
// Log variables with names
const a = 4;
const b = 4;
const c = 4;
console.log({a, b, c }) // {a: 4, b: 4, c: 4}
// Random hex color
"#" + Math.floor(Math.random() * 16777215).toString(16);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment