Use the shortest code to fix the array.

Source: Internet
Author: User

Get rid of the array with the shortest code, and welcome to the point of inadequacy.

       /* Let numbers = [3, 8, ten, +];        Let num_test = [4, 5, ten, +]; */ = [3, 8, ten, 20].concat ([4, 5, ten, +]);                  =[];            $.each (Arr_num, (item, index)= {               res.lengthnull  ;         });        Console.log (res);         //

The previous wording for the use of some es6 is relatively brief, and the simple jquery notation is:

varNumbers = [3, 8, 10, 18, 20]; var num_test= [4, 5, 10, 18, 20]; varArr_num =Numbers.concat (num_test); varres =[]; $.each (Arr_num,function(item, index) {if(Res.length==0 | | ($.inarray (Index,res) ===-1) {res.push (index); }Else{return ;}        });        Console.log (RES); //[3, 8, ten, 4, 5]

What about the question of return in the ternary operator, condition? Example 1: Example 2;

Online search without fruit, after practice to know (PS: ternary operator also called the trinocular operator)

The ternary operator/three-mesh operator Example 1 and Example 2 cannot be a statement that must have a value, and return is not a valid valued expression.

The first judgment I wrote was:

return ; // Error // syntaxerror:expected expression, got keyword ' return '

About return:

Retrun true; Returns the correct processing result.  return false; Returns the processing result of the error, terminating processing. Return  the control back to the page return null to continue execution

Therefore, when using the ternary operator really need to use return, you can directly write the result of return, to avoid the use of return easy to jump wrong

Use the shortest code to fix the array.

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.