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
// 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; |
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
// 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) => { |