Front-end Job Interview Questions


Front-end Job Interview Questions

前端面試

https://github.com/h5bp/Front-end-Developer-Interview-Questions

https://github.com/MaximAbramchuck/awesome-interview-questions

https://thatjsdude.com/interview/index.html

http://caibaojian.com/fedbook/practice/front-end-interview.html


柯里化函數


function curry(fn) {
    var slice = [].slice;
    var len = fn.length;

    return function curried() {
        var args = slice.call(arguments);
        if (args.length >= len) {
            return fn.apply(null, args);
        }

        return function () {
            return curried.apply(null, args.concat(slice.call(arguments)));
        };
    };
}

var add = curry(function (a, b, c, d) {
    return a + b + c + d;
});

console.log(add(1)(2)(3)(4)); // 10
console.log(add(1, 2, 3)(4)); // 10
console.log(add(1)(2, 3)(4)); // 10

https://segmentfault.com/q/1010000004342477

add(2)(5); // 7 & 柯里化 curry

js 實現, 函數 add(1)(2)(3); 無限極累加


"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2019-01-01
 *
 * @description add & curry
 * @augments
 * @example
 *
 */

function add( seed ) {
    function retVal( later ) {
        return add( seed + later );
    }
    retVal.toString = function() {
        return seed;
    };
    return retVal;
}
console.log(add(1)(2)(3).toString());
// 6
console.log(add(1)(2)(3));
// ƒ 6

function addBug(a){
    function s(b){
       a = a+b;
       return s;
    }
    s.toString = function(){return a;}
    return s;
}
console.log(addBug(1)(2)(3)(4));
// ƒ 10

addBug(1);
// ƒ 1
let x = addBug(1)(2);
// ƒ 3
x;
// ƒ 3
alert(addBug(1)(2)(3)(4));
// alert: 10
// true


refs

https://llh911001.gitbooks.io/mostly-adequate-guide-chinese/content/ch4.html

https://www.cnblogs.com/pengchen/p/5434705.html

https://www.cnblogs.com/oxspirt/p/5436629.html

https://www.ruanyifeng.com/blog/2015/02/flexible-javascript.html

wat

https://www.destroyallsoftware.com/talks/wat



Flag Counter

&copyxgqfrms 2012-2020

www.cnblogs.com 發布文章使用:只允許注冊用戶才可以訪問!



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM