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
/** | |
* ES6 and featured code | |
*/ | |
let combineGetters = (...getters) => state => getters.reduce(({ payload }, getter) => ({ payload: getter(state, payload) }), { payload: state }); | |
let findPairsInSorted = arr => value => { | |
let results = []; | |
let len = (arr && arr.length) || 0; | |
if (len < 1) { | |
return results; |
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
/** | |
* mostly ES5 without featured code | |
* except for let and arrow functions which are better for reading and understanding | |
* | |
* FYI | |
* 1) a => a > 0 equals function (a) { return a > 0; } and is just a syntax sugar | |
* 2) let is used as an example of best practices | |
* 3) map is used to change the element to the result | |
* [-3, 1, 15].map(a => a < 0 ? [a, 0] : [0, a]) => [[-3, 0], [0, 1], [0, 15]] | |
* 4) filter is used to get only those elements which function is true for the condition |
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
function findPairsInSorted(arr, value) { | |
let results = []; | |
let len = arr ? arr.length : 0; | |
if (len < 2) { | |
return results; | |
} | |
for (let i = 0, j = len - 1; i < j;) { | |
let diff = value - arr[i]; | |
if (diff < arr[j]) { | |
j--; |
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
/** | |
* The only difference here is that sign(0) = 1 | |
*/ | |
let sign = a => { | |
let signBit = a >>> 31; | |
return signBit * -1 + (1 - signBit) * 1; | |
}; | |
let abs = a => a * sign(a); |
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
/** | |
* For clafirying go to https://css-tricks.com/the-difference-between-throttling-and-debouncing/ | |
* | |
*/ | |
count DEFAULT_DEBOUNCE_TIME = 400; | |
const DEFAULT_THROTTLE_TIME = 400; | |
let debounce = (fn, time = DEFAULT_DEBOUNCE_TIME) => { | |
let timeoutId; | |
return (...args) => { |
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
let LazyArray = (() => { | |
let _arr = []; | |
let _ops = []; | |
const isEmpty = v => v === null || v === undefined; | |
const combine = (v, ...fns) => { | |
let result = v; | |
for (let { type, fn } of fns) { |
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 CarFactory = ({ name }) => { | |
let distancePassed = 0; | |
let driveHistory = []; | |
let car = { | |
name, | |
beep({ message = '' } = {}) { | |
console.log(`${name}: Beeeeep! ${message}`); | |
}, |
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 unary = { | |
identity: x => x, | |
inc: x => x + 1, | |
dec: x => x - 1, | |
double: x => 2 * x, | |
sqr: x => x * x, | |
identityf: x => () => unary.identity(x), | |
}; |
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
// TODO: | |
// 1) optimise search by sorting strings | |
/* | |
* words: Factory for finding words | |
* | |
* letters: String or Array, | |
* length: Number, | |
*/ | |
const words = (() => { |
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
/* different parameters based on number of elements */ | |
.selector:nth-last-child(2):first-child { | |
&, & ~ .selector { | |
// setting parameter, i.e.: flex-basis: 50%; | |
} | |
} | |
.selector:nth-last-child(3):first-child { | |
&, & ~ .selector { | |
// setting parameter, i.e.: flex-basis: 33.33%; |
OlderNewer