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
a = [ { name: 'bill', group: 'b' }, | |
{ name: 'ann', group: 'a' }, | |
{ name: 'ken', group: 'k' }, | |
{ name: 'alex', group: 'a' } ] | |
_.reduce((sum, v) => { | |
const { name, group } = v; | |
const current = _.getOr([], [group, name])(sum); | |
return _.set([group, name], [...current, v])(sum); | |
}, {})(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
shuffle_array = arr => | |
arr | |
.map(a => [a, Math.random()]) | |
.sort(([, lr], [, rr]) => lr - rr) | |
.map(([a]) => a); | |
user_action_for_state = (state, randy) => { | |
if (state === 'p' || state === 'ps' || state === 'psa' || state === 'psam') { | |
if (randy < 0.7) { | |
return primary_action_names[state[state.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
shuffle_array = arr => | |
arr | |
.map(a => [a, Math.random()]) | |
.sort(([, lr], [, rr]) => lr - rr) | |
.map(([a]) => 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
const times = require('lodash/fp/times'); | |
const map = require('lodash/fp/map'); | |
const sample = require('lodash/fp/sample'); | |
const maxBy = require('lodash/fp/maxBy'); | |
const find = require('lodash/fp/find'); | |
const join = require('lodash/fp/join'); | |
const flow = require('lodash/fp/flow'); | |
const get = require('lodash/fp/get'); | |
const sum = require('lodash/fp/sum'); | |
const constant = require('lodash/fp/constant'); |
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 a = [ | |
{ a: 'one', b: 4 }, | |
{ a: 'two', b: 1 }, | |
{ a: 'three', b: 4 }, | |
{ a: 'four', b: 2 } | |
]; | |
function argmaxAll(getterFunction, arr) { | |
return reduce( | |
([max, arr], curr) => { |
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
_.reduce( | |
([numItemsSeen, mean], num) => [ | |
numItemsSeen + 1, | |
mean + (num - mean) / (numItemsSeen + 1) | |
], | |
[0, 0] | |
)([3, 4, 5, 6, 10, 100, 9]); |
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 diceTriplets = sides => | |
_(sides) | |
.range() | |
.flatMap(a => | |
_(sides) | |
.range() | |
.flatMap(b => | |
_(sides) | |
.range() | |
.map(c => [a + 1, b + 1, c + 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
// modification version | |
function once(f) { | |
let hasRun = false; | |
let result; | |
return () => { | |
if (!hasRun) { | |
result = f(); | |
hasRun = true; | |
} | |
return result; |
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 _ = require('lodash'); | |
function supersetInner(src) { | |
if (src.length === 0) return []; | |
const withouts = _.map(src, elem => superset(_.without(src, elem))); | |
return [src, ..._.flatten(withouts)]; | |
} | |
function superset(src) { |
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 fs = require('fs'); | |
const gm = require('gm'); | |
function getSize(image) { | |
return new Promise((resolve, reject) => { | |
image.size((err, size) => { | |
if (err) { | |
reject(err); | |
return; | |
} |
NewerOlder