Skip to content

Instantly share code, notes, and snippets.

/*
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);
@Pierre-M
Pierre-M / lonelyNumber.js
Created June 7, 2021 08:06
Weekly question from Cassidy Williams newsletter (07/06/2021)
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;
@Pierre-M
Pierre-M / pizza-counter.js
Created September 28, 2020 08:27
Cassidoo newsletter question - 28/09/2020
/*
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;
@Pierre-M
Pierre-M / arrayFilter.js
Created January 7, 2020 08:52
Interview question by Cassidy Williams (2020-01-06 newsletter)
Array.prototype.filter = function(predicate) {
const filteredArray = [];
this.forEach((el, idx) => {
if (predicate(el, idx, this)) {
filteredArray.push(el);
}
});
return filteredArray;
@Pierre-M
Pierre-M / binaryQueue.js
Created December 17, 2019 09:17
Interview question by Cassidy Williams (2019-12-16 newsletter)
/*
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