Several Ali pen questions

Source: Internet
Author: User

1.

 var  data = {a:  1 b:  2 3, D:  4 Span style= "color: #000000;"   >   };  var  result = Object.keys (data). Filter ( function   (x) { return  D                ATA[X] > 2;   });  Console.log (result); //["C", "D"] 

/*
Explanation: Object.keys () outputs an enumerable property name as an array, object.keys (data) returns an array of ["A", "B", "C", "D"]
Filter () arrays that are an iterative method that runs the given function for each item in a group, and returns the number of items that the function returns True. ,
namely: function (item, index, array)
*/

2. Creation of objects to be examined

  function  obj (name) {       if  (name) {           returnnew  obj (name);       }          }   Obj.prototype.name  = "name2";    var a = obj ("name1");    var New obj;   Console.log (a.name);   // "Name1"   Console.log (b.name);  // "Name2"

3. Fibonacci Sequence

   function  Getnthfibonacci (count) {      if(Count < 2) {         return 1;       Else {         return Arguments.callee (count-1) + Arguments.callee (count-2// Use Arguments.callee to disassociate the function from the name of the functor      }   }   Console.log (Getnthfibonacci (0));  // 1   Console.log (Getnthfibonacci (4));  // 5

Several Ali pen questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.