zoukankan      html  css  js  c++  java
  • JavaScript 中的不完全函数

    function array(a,n){
                    return Array.prototype.slice.call(a,n || 0);
                }
                //the arguments to this function are passed on the left
                function particalLeft(f){
                    var args = arguments;
                    return function(){
                        var a = array(args,1);
                        a = a.concat(array(arguments));
                        return f.apply(this,a);
                    }
                }
                //the arguments to this function are passed on the right
                function particalRight(f){
                    var args = arguments;
                    return function(){
                        var a = array(arguments);
                        a = a.concat(array(args, 1));
                        return f.apply(this, a);
                    }
                }
                //The arguments to this function serve as a templete, Undefined values in the argument list are filled in with values from the inner set
                function partical(f){
                    var args = arguments;
                    return function(){
                        var a = array(arguments);
                        var length = a.length;
                        var j = 0;
                        for(var i = 0; i< length; i++){
                            if(a[i] === undefined){
                                a[i] = arguments[j++];
                            }
                        }
                        a = a.concat(array(arguments,j));
                        return f.apply(this,a);
                    }
                }
                function f(x,y,z){
                    return x*(y-z);
                }
                var result1 = particalLeft(f,2,3)(4);
                var result2 = particalRight(f,2)(3,4);
                var result3 = partical(f,undefined)(2,3,4);
                console.log(result1);
                console.log(result2);
                console.log(result3);
  • 相关阅读:
    滑动窗口法学习
    209. Minimum Size Subarray Sum
    485. Max Consecutive Ones
    27. Remove Element
    167. Two Sum II
    561. Array Partition I
    344. Reverse String
    14. 最长公共前缀
    layui上传文件时出现 请求上传接口出错
    Linux-5.13将初步支持苹果M1 Soc
  • 原文地址:https://www.cnblogs.com/fanhc/p/3255020.html
Copyright © 2011-2022 走看看