This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
I think a good way of dealing with the layers and avoid unused variables trap : | |
- for most cases : directly use the 2d layer (main text colors, icon colors... that don't need specificy and are shared by all components) | |
- for specific cases that need a 3d (aka component) layer : store variables close to their usage, in the component itself | |
- last and corner case : 3d layer shared by 2 or more components -> store variables in common variables file as we do today for all variables | |
*/ | |
$my-component-text-color: $text-color-main; // let's store that one as it's used in another variable | |
$my-component-shadow: 0 4px 8px rgba($my-component-text-color, 0.2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const lonelyNumber = (...numbers) => { | |
if (numbers.length !== 3) { | |
return console.warn('You must provide 3 numbers.'); | |
} | |
if (numbers.every((item, index, items) => item === items[0])) return 1; | |
const lonelyNumbers = numbers.filter((item, index, items) => { | |
return items.filter(i => i === item).length === 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given an array of people objects | |
(where each person has a name and a number of pizza slices they’re hungry for) | |
and a number for the number of slices that the pizza can be sliced into, | |
return the number of pizzas you need to buy. | |
*/ | |
function computeNeededPizzasCount(eaters, nbrOfSlices) { | |
const neededSlices = eaters.reduce((totalSlices, eater) => { | |
return totalSlices + eater.num; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.filter = function(predicate) { | |
const filteredArray = []; | |
this.forEach((el, idx) => { | |
if (predicate(el, idx, this)) { | |
filteredArray.push(el); | |
} | |
}); | |
return filteredArray; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given a positive number N, generate binary numbers between 1 to N | |
using a queue-type structure in linear time. | |
*/ | |
function binaryQueue(x) { | |
return [...Array(x).keys()] // let's build an array of numbers from 0 to x | |
.slice(1) // drop the first element to have an array from 1 to x | |
.map(k => k.toString(2)) // now we have an array of binaries from 1 to x as strings | |
.map(e => parseInt(e, 10)) // now we have an array of numbers from 1 to x in binaries |