• Interview handwritten code list


    Anti chattering function const debounce = (fn, wait) => { let _ = ” return (…arg) => { clearTimeout(_) _ = setTimeout(() => { fn.apply(this, arg) }, wait) } } input.addEventListener(“input”, debounce(ajax, 1000)); Throttling function const throttle = (fn, s) => { let a = +new Date(), _ return (…arg) => { let b = +new Date() – a if (b > s) { _ = setTimeout(() => { fn(arg); _ = ” }, s) a = +new Date() } } } input.addEventListener(“input”, throttle(ajax, 1000)); Deep copy (solve circular reference) function clone(target, map = new WeakMap()) { if (typeof target === ‘object’) { let cloneTarget = Array.isArray(target) ? [] : […]

  • Display component and container component (by Dan Abramov, developer of Redux)


    This article is translated fromPresentational and Container ComponentsThe author of the article isDan Abramov, he is also the author of Redux and create react app.In the actual development process of using react + Redux technology stack, a very good understanding of the concept of container component and display component is the basis of developing an […]

  • [dichotomy algorithm] PHP implementation of binary search algorithm


    $a = array(1,2,33,24,15,16,7,8); function find2($a,$findValue){ /** * [url= home.php?mod=space&uid=170990 ]@Name [/ url] dichotomy search algorithm * [url= home.php?mod=space&uid=686208 ]@Author [/ url] * [url= home.php?mod=space&uid=952169 ]@Param [/ url] $a: array passed, $findvlaue: value to find * [url= home.php?mod=space&uid=155549 ]@Return [/ url] true found, false not found */ sort($a); $heigh = count((array)$a)-1; $low = 0; while ($heigh>=$low) […]

  • Leetcode 35 search insertion location


    Leedcode35 search insertion location The main idea of solving the problem is that the target array is ordered array, and the efficiency of searching by dichotomy is higher //Title: //Given a sort array and a target value, find the target value in the array, And returns its index. If the target value does not exist […]

  • The longest common prefix


    Address: https://leetcode-cn.com/probl… Title Description Analysis topic The most intuitive feeling about this problem is: First string foundtarget Perform a horizontal scan by column My code is as follows: /** * @param {string[]} strs * @return {string} */ var longestCommonPrefix = function(strs) { if (!strs || !strs.length) { return ” } let target = strs[0] for […]

  • Binary search (C language)


    Dichotomy is an efficient search method, which is suitable forIt’s in orderArray Basic thinking Search and judge from the middle number of the array. If it is not the number to be searched, compare the size. Then search and judge from the middle on one side of the two sides separated from the middle, and […]

  • How to find out whether an ordered array contains a value in PHP (binary search)


    Problem: for an ordered array, how to judge whether a given value exists in the array.   Idea: the simplest way to judge whether there is an array is to directly loop the array and compare each value. But for an ordered array, this writing does not make good use of the “ordered” feature. So […]