Skip to content

Instantly share code, notes, and snippets.

@markninja96
markninja96 / react-debouncing.md
Created November 19, 2020 14:38 — forked from simonw/react-debouncing.md
React debouncing pattern for API calls

React debouncing pattern for API calls

Classic debounce function:

const debounce = (fn, delay) => {
      let timer = null;
      return function (...args) {
          const context = this;
          timer && clearTimeout(timer);

timer = setTimeout(() => {

@markninja96
markninja96 / KMP.js
Created August 20, 2020 21:34 — forked from blasten/KMP.js
String matching based on the KMP algorithm. This how `String.prototype.indexOf` is generally implemented.
// Construct a table with table[i] as the length of the longest prefix of the substring 0..i
function longestPrefix(str) {
// create a table of size equal to the length of `str`
// table[i] will store the prefix of the longest prefix of the substring str[0..i]
var table = new Array(str.length);
var maxPrefix = 0;
// the longest prefix of the substring str[0] has length
table[0] = 0;