Skip to content

Instantly share code, notes, and snippets.

View Kiwka's full-sized avatar
🦄
Let's make this world a better place to live in

Olena Sovyn Kiwka

🦄
Let's make this world a better place to live in
View GitHub Profile
@Kiwka
Kiwka / DeMorgansLaws.js
Created May 5, 2020 13:00
DeMorgan’s Laws
!(A || B) === !A && !B
!(A && B) === !A || !B
@Kiwka
Kiwka / options.js
Created February 6, 2020 21:48
Calculating options by using cartesian product
cartesian([arr1, arr2, arr3, arr4]).forEach(
(option1, option2, option3, option4) => {
// use option1, option2, option3, option4 here
});
@Kiwka
Kiwka / options.js
Created February 6, 2020 21:46
Brute-force solution to get all options for a few arrays
arr1.forEach(option1 => {
arr2.forEach(option2 => {
arr3.forEach(option3 => {
arr4.forEach(option4 => {
// use option1, option2, option3, option4 here
});
});
});
});
@Kiwka
Kiwka / cartesianProduct.js
Created January 27, 2020 22:05
Cartesian product
const f = (a, b) => [].concat(...a.map(d => b.map(e => [].concat(d, e))));
const cartesian = (a, b, ...c) => (b ? cartesian(f(a, b), ...c) : a);
@Kiwka
Kiwka / blogEntry.js
Created December 4, 2019 11:55
Example of the named type for string types variable
export type BlogEntryId = string;
type BlogEntryType = {|
id: BlogEntryId,
...
|};
const blogEntry: = {
id: 'ddjj38302mmd92m2k2',
...
@Kiwka
Kiwka / .flowconfig
Created December 3, 2019 22:13
add suppress type in the flow config
[options]
suppress_type=FixMeAny
@Kiwka
Kiwka / .flowconfig
Created December 3, 2019 15:30
adding suppress comment to flow config
[options]
suppress_comment= \\(.\\|\n\\)*\\$FlowExpectError
@Kiwka
Kiwka / .flowconfig
Created December 3, 2019 13:57
Example of the config for preventing imports from untyped files
[strict]
untyped-import
@Kiwka
Kiwka / solution.js
Last active December 2, 2019 20:42
Advent of Code - 2019 - Day 2
// part 1
const array = $0.textContent.split(',').map(Number);
array[1] = 12;
array[2] = 2;
let i = 0;
while (i < array.length) {
const current = array[i];
@Kiwka
Kiwka / solution.js
Last active December 1, 2019 14:01
Advent of Code - 2019 - Day 1 - JavaScript
// part 1
const fuel = x => Math.floor(x/3) - 2;
$0.textContent.split("\n").map(Number).map(fuel).filter(i => i > 0).reduce((a, b) => a + b, 0)
// part 2
($0.textContent.split("\n").map(Number).filter(i => i > 0).map(mass => {const res = []; let i = mass; while (i > 0) {i = fuel(i); res.push(i)} return res})).flat().reduce((a, b) => a + b, 0)