js題集24

來源:互聯網
上載者:User

標籤:說明   ext   object   time   一個   one   node   自己   []   

1.實現MagicFunction

MagicFunction(3) == 3; // should return true

MagicFunction(1, 2) == 3; // should return true

MagicFunction(1, 3)(2) == 6; // should return true

MagicFunction(1, 2)(3, 4, 5)(6)(7, 10) == 38; // should return true *1+2+3+4+5+6+7+10=38;

 

2.實現如下結果

seven(times(five())); // must return 35

four(plus(nine())); // must return 13

eight(minus(three())); // must return 5

six(dividedBy(two())); // must return 3

 

//your code........補充下面代碼

 

function zero() {}

function one() {}

function two() {}

function three() {}

function four() {}

function five() {}

function six() {}

function seven() {}

function eight() {}

function nine() {}

 

function plus() {}

function minus() {}

function times() {}

function dividedBy() {}

 

3.實現lazy函數

new Lazy()

      .add(filterNumbers)

      .add(filterRange, 2, 7)

      .add(max)

      .invoke([1, 8, 6, [], "7", -1, {v: 5}, 4]); //6

 

//你可能需要下列函數用來測試結果

function max() {

    return Math.max.apply(null, arguments);

}

 

function filterNumbers() {

  return Array.prototype.filter.call(arguments, function(value) {

    return isNumeric(value);

  });

}

 

function isNumeric(n) {

  return !isNaN(n) && Number(n) === n;

}

 

function filterRange(min, max) {

  var args = Array.prototype.slice.call(arguments, 2);

  return Array.prototype.filter.call(args, function(value) {

    return min <= value && value <= max;

  });

}

 

4.實現--自己猜

function func1(arg1, arg2) { ... }

 

var map = createArgumentMap(func1,‘valueOfArg1‘, ‘valueOfArg2‘);

console.log(map[‘arg1‘]);  // writes ‘valueOfArg1‘

console.log(map[‘arg2‘]);  // writes ‘valueOfArg2‘

 

5.實現extend 

extend( {a: 1, b: 2}, {c: 3} ) // should === {a: 1, b: 2, c: 3}

extend( {a: 1, b: 2}, {c: 3}, {d: 4} ) // should === {a: 1, b: 2, c: 3, d: 4}

extend( {a: 1, b: 2}, {a: 3, c: 3} ) // should  === {a: 1, b: 2, c: 3}

extend( {a: false, b: null}, {a: true, b: 2, c: 3} ) // should  === {a: false, b: null, c: 3}

。。。。。。。。

//補充:原出題者情況說明較少 筆者補充一個arguments的情況過濾掉非object

//NODE 下 可以直接用isObject函數進行 非node下

//參考如下:

//

function isObject(val) {

    if (val === null) { return false;}

    return ( (typeof val === ‘function‘) || (typeof val === ‘object‘) );

}

 

1)arguments=

{

‘0‘: { a: 1, b: 2, length: 6 },

‘1‘: [],

‘2‘: ‘nope‘,

‘3‘: false,

‘4‘: [Function],

‘5‘: { c: 3, a: 3 }

}//   要過濾掉1,2,3,4

js題集24

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.