Instantly share code, notes, and snippets.

Christopher Elwell celwell

  • Los Angeles, CA
View GitHub Profile
View memoize.js
// Takes a function, f, and returns a memoized version of f.
// Note: only memoize pure, idempotent functions
var memoize = function (f) {
let store = new Map();
return function (...args) {
const k = JSON.stringify(args);
return (store.has(k) ?
store.get(k) :
store.set(k, f(...args)).get(k));
View Merge Sort in JavaScript.js
// helper fn used by merge_sort; merges two arrays into sorted order
var merge = function (left, right) {
let merged = [],
i = 0, // left array index counter
j = 0; // right array index counter
while (i < left.length && j < right.length) {
if (left[i] < right[j]) {
merged.push(left[i]);
i++;
View Thread-last and first.clj
(-> test-results
(->> (map #(list (:id %) (:prefill_config %))))
flatten
(->> (apply hash-map))
keywordize-keys
(select-keys (map keyword current-form-ids)))