Skip to content

Instantly share code, notes, and snippets.

@40detectives
40detectives / RealMemoizationComponent.jsx
Last active March 26, 2022 15:38
useMemo hook with a real memoization storage (using recursive fibonacci)
// This is an example of Reacts's useMemo hook,
// useMemo only really does a "render memoization" for react internally, i.e.: skipping calculation in some renders.
// in this example I try to circumvent that and make useMemo to also cache previous calls in an object.
// ALSO: the ideal way of doing this for fibonacci would be doing the memoization in the fibonacci function itself,
// that way you could remember all the n-1 fibonacci numbers after just one fibonacci(n) call.
import { useState, useMemo } from "react";
const fibonacci = (n) => {
@40detectives
40detectives / partial_function_application.js
Created November 3, 2020 20:33 — forked from pauladam/partial_function_application.js
Practical example of function currying in JS
// I have some code that needs to use the following
// construct repeatedly
for(i=0;i<classes.length;i++){
var c = classes[i];
for(j=0;j<centers.length;j++){
var k = centers[k];
// do something with [c,k], like,
// demand[[c,k]] = expression;