48.reduce sort, go to weight, take maximum value

Source: Internet
Author: User

vararr = [2,4,1,-1,9]//Take maximum valuevarMaxValue = Arr.reduce (function(A, b) {returnA>b?A:B}) Console.trace (' Maxvalue-> ', MaxValue)//array de-weightvarARR1 = [2,3,4,5,6,7,4,6,3]let $arr 1= Arr1.reduce (function(Prev,number) {console.log (prev)if(Prev.indexof (number) ===-1) {Prev.push (number)}returnprev;},[]) Console.trace (' $arr 1-> ', $arr 1)//SortvarARR2 = ["Zebras", "dogs", "elephants", "Penguins"].sort (function(A, b) {returnA.length-b.length;}); Console.log (ARR2)

You can expand to compare the maximum value of an attribute in an array object, and examine an attribute in the array object ... So it's still very powerful.

48.reduce sort, go to weight, take maximum value

Related Article

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.