Destructuring props in styled-components
JavaScriptstyled-components
Read fire tipFinding values that exist in only one of two arrays is called “XOR”, or “exclusive OR”. It gets us all values that appear in either the first OR the second array, but not both.
// takes two arrays and returns all elements that appear in only one of them
const xor = (first, second) => [
...first.filter(element => !second.includes(element)),
...second.filter(element => !first.includes(element))
]
// `xor` returns all elements that appear in only one of the two arrays
xor([1, 2, 3, 4, 5], [2, 3, 4, 5, 6]) // ⇒ [1, 6]
// an element can appear multiple times, but only in one array
xor(['beep', 'beep', 'boo', 'boo'], ['beep']) // ⇒ ['boo', 'boo']
We cannot use the typeof operator in JavaScript to check if something is an array or not. Luckily, there is a helper function on the Array prototype for that.
Just as we can destructure all other objects, we can destructure functions like log() and warn() directly out of the console object.