Skip to content

Instantly share code, notes, and snippets.

View marcelabomfim's full-sized avatar
🏳️‍🌈
Happy

Marcela Bomfim marcelabomfim

🏳️‍🌈
Happy
View GitHub Profile
/*
* Remove duplicate object entries from an array
* @param {Object[]} arr - the array of objects
* @param {string} prop - the property used for comparison
*
* @example
* // returns [{ id: 1, name: 'apple', id: 3, name: 'orange'}]
* removeDuplicatesByProp([{ id: 1, name: 'apple' }, { id: 2, name: 'apple' }, { id: 3, name: 'orange' }], 'name');
*
* @returns {Object[]}
@marcelabomfim
marcelabomfim / findCommonElements.js
Created June 15, 2018 16:08
Javascript | Find common elements in multiple arrays
const findCommonElements = arrays =>
arrays.shift().reduce((res, v) => {
if (res.indexOf(v) === -1 && arrays.every((a) => {
return a.indexOf(v) !== -1
})) res.push(v)
return res
}, []);
// Example
const arrays = [
@marcelabomfim
marcelabomfim / bookmark.min.js
Created May 17, 2018 12:17 — forked from zaydek-old/bookmark.min.js
A simple CSS debugger. Learn more here: https://medium.freecodecamp.org/88529aa5a6a3. To use, bookmark "Debug CSS" at https://zaydek.github.io/debug.css
/* debug.css | MIT License | zaydek.github.com/debug.css */ if (!("is_debugging" in window)) { is_debugging = false; var debug_el = document.createElement("style"); debug_el.append(document.createTextNode(`*:not(path):not(g) { color: hsla(210, 100%, 100%, 0.9) !important; background: hsla(210, 100%, 50%, 0.5) !important; outline: solid 0.25rem hsla(210, 100%, 100%, 0.5) !important; box-shadow: none !important; }`)); } function enable_debugger() { if (!is_debugging) { document.head.appendChild(debug_el); is_debugging = true; } } function disable_debugger() { if (is_debugging) { document.head.removeChild(debug_el); is_debugging = false; } } !is_debugging ? enable_debugger() : disable_debugger();