Return largest Numbers in Arrays-freecodecamp algorithm topic

Source: Internet
Author: User

Return largest Numbers in Arrays (Find out the maximum number of multiple arrays)
  1. Requirements
    • The large array contains 4 decimal groups, each of which finds the maximum value in each decimal group, and then concatenates them together to form a new array.
  2. Ideas
    • Use the For loop to iterate through the algebraic groups and arr[i] access each element of the array in a way.
    • In the first layer for loop, define the variable temp as the first element of the subarray. Assigns the maximum value of the Subarray to temp in the second for loop, and then assigns the maximum value of the subarray to the corresponding element of the large array at the end of a layer of loops
  3. Code
    • 1 functionLargestoffour (arr) {2   //please write down your code here.3    for(varI =0;i<arr.length;i++){4     vartemp = arr[i][0];5      for(varJ =1;j<arr[i].length;j++){6       if(Temp <Arr[i][j]) {7temp =Arr[i][j];8       }9     }TenArr[i] =temp; One   } A    -   returnarr; - } the  -Largestoffour ([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
  4. RELATED LINKS
      • Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Comparison_Operators

Return largest Numbers in Arrays-freecodecamp algorithm topic

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.