Skip to content

Instantly share code, notes, and snippets.

View blazecolour's full-sized avatar
🔥

Sergei Shitikov blazecolour

🔥
View GitHub Profile
const getTrib = n => {
let [x, y, z] = [0, 1, 1]
for (let i = 2; i < n; i += 1) {
[x, y, z] = [y, z, x + y + z]
}
return x
}
const make = x => {
const fn = h => x => (typeof x === 'function')
? h(x)
: fn(y => y(x, h(y)))
return fn(y => x);
}
const sum = (a, b) => a + b
const mul = (a, b) => a * b
const deepClone = (obj) => {
if (obj === null) return null
return Object.keys(obj).reduce((acc, key) => {
acc[key] = Array.isArray(obj[key])
? [...obj[key]]
: typeof obj[key] === 'object'
? deepClone(obj[key])
: obj[key]
const flatten = (obj, prefix = '') =>
Object.keys(obj).reduce((acc, k) => {
const pre = prefix.length ? prefix + '.' : ''
if (typeof obj[k] === 'object') {
Object.assign(acc, flatten(obj[k], pre + k))
}
else acc[pre + k] = obj[k]
return acc
}, {})
const mergeObjects = ([...args]) =>
args.reduce(
(acc, obj) =>
Object.keys(obj).reduce((_, key) => {
acc[key] = acc[key] ? [...acc[key], obj[key]] : [obj[key]]
return acc
}, {}),
{}
)
@blazecolour
blazecolour / vscode-extensions
Created June 20, 2019 07:29
~/.vscode/extensions
abusaidm.html-snippets-0.2.1
bradgashler.htmltagwrap-0.0.7
christian-kohler.npm-intellisense-1.3.0
christian-kohler.path-intellisense-1.4.2
dbaeumer.vscode-eslint-1.9.0
dsznajder.es7-react-js-snippets-2.3.0
eamodio.gitlens-9.8.2
eg2.vscode-npm-script-0.3.7
esbenp.prettier-vscode-1.9.0
flowtype.flow-for-vscode-1.1.3
const before = (count, fn) => {
let called = 0;
return (...args) => {
if (called >= count) return;
called += 1;
return fn(...args);
};
};
class Sleep {
constructor(timeout) {
this.timeout = timeout;
}
then(resolve, reject) {
const startTime = Date.now();
setTimeout(() => resolve(Date.now() - startTime), this.timeout);
}
}
const swap = (items, firstIndex, secondIndex) => {
const temp = items[firstIndex];
items[firstIndex] = items[secondIndex];
items[secondIndex] = temp;
};
const partition = (items, left, right) => {
let pivot = items[Math.floor((right + left) / 2)];
let i = left;
let j = right;
const bubblesort = arr => {
const count = arr.length - 1;
let max = null;
for (let i = 0; i < count; i++) {
for (let j = 0; j < count - i; j++) {
if (arr[j] > arr[j + 1]) {
max = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = max;