Js simple sorting algorithm

algorithm:

// basic algorithms: flattened array 
        // using ...    
        // only two flattened   
        //
         {
            let arr = [1,[2,3],[4,5]];
              let arr2 = ''    ;
              arr2=[].concat(...arr)
              console.log(arr2)
        }
        

        // recursive algorithm 
        {
            let arr=[1,[2,3],[[[4,5]]]];
            flatten(arr);
            function flatten(arr){
                return [].concat(
                        ...arr.map(x => Array.isArray(x)?flatten(x):x)        
                )
            }
            console.log(flatten(arr))
        }

        // function throttling algorithm from the last execution of more than 60 milliseconds to perform 
        // idea: After performing throttle, lock is a lock only when the lock is false when the execution FUNC, 
        // the lock needs to throttle since the last separated by 60 ms to perform is to false 
        {
             function Throttle (FUNC, Delay = 60 ) {
                let lock = false;
                return (...args) =>{
                    if(lock){return}
                    func(...args);
                    lock = true;
                setTimeout( () =>{lock = false}, delay)    
                }
            }
        }

        // function throttle Second, how many times after the arithmetic operation before the implementation 
        // ideas: non-stop operation, the timer has been repeated overlay executed, the timer i will always be repeated, 
        // needed no time to perform throttle when the last timer cleared i, 
        {
             function Throttle (FUNC, Delay = 300, i = null ) {
                 return (args ...) => {
                    clearInterval(i);
                    i=setTimeout(func.bind(null,...args),delay);
                    //i=setTimeout((...args) =>func(...args),delay);// 同上

                }
            }
        }

Guess you like

Origin www.cnblogs.com/wxyblog/p/12047594.html