要求:

右边大数组中包含了4个小数组,分别找到每个小数组中的最大值,然后把它们串联起来,形成一个新数组。

提示:你可以用for循环来迭代数组,并通过arr[i]的方式来访问数组的每个元素。

结果:

  • largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]) 应该返回一个数组.
  • largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]) 应该返回[27,5,39,1001].
  • largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]])应该返回 [9, 35, 97, 1000000].

代码:

 function largestOfFour(arr) {
// You can do this!
var newarr=[]; for (var i=0;i<arr.length;i++){
var maxNumber=0;
for (var j=0;j<arr[i].length;j++){
if(arr[i][j]>maxNumber){
maxNumber=arr[i][j];
}
}
newarr[i]=maxNumber;
}
return newarr;
} largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

FreeCodeCamp:Return Largest Numbers in Arrays的更多相关文章

  1. freeCodeCamp:Return Largest Numbers in Arrays

    右边大数组中包含了4个小数组,分别找到每个小数组中的最大值,然后把它们串联起来,形成一个新数组. 提示:你可以用for循环来迭代数组,并通过arr[i]的方式来访问数组的每个元素. /*思路 for循 ...

  2. Return Largest Numbers in Arrays

    题目要求 右边大数组中包含了4个小数组,分别找到每个小数组中的最大值,然后把它们串联起来,形成一个新数组. 提示:你可以用for循环来迭代数组,并通过arr[i]的方式来访问数组的每个元素. 答题思路 ...

  3. FCC JS基础算法题(5):Return Largest Numbers in Arrays(找出多个数组中的最大数)

    题目描述: 找出多个数组中的最大数右边大数组中包含了4个小数组,分别找到每个小数组中的最大值,然后把它们串联起来,形成一个新数组.提示:你可以用for循环来迭代数组,并通过arr[i]的方式来访问数组 ...

  4. Return Largest Numbers in Arrays-freecodecamp算法题目

    Return Largest Numbers in Arrays(找出多个数组中的最大数) 要求 大数组中包含了4个小数组,分别找到每个小数组中的最大值,然后把它们串联起来,形成一个新数组. 思路 用 ...

  5. 544. Top k Largest Numbers【medium】

    Given an integer array, find the top k largest numbers in it.   Example Given [3,10,1000,-99,4,100] ...

  6. Top k Largest Numbers

    Given an integer array, find the top k largest numbers in it. Example Given [3,10,1000,-99,4,100] an ...

  7. No.004:Median of Two Sorted Arrays

    问题: There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the ...

  8. LeetCode:4_Median of Two Sorted Arrays | 求两个排序数组的中位数 | Hard

    题目: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...

  9. LeetCode2:Median of Two Sorted Arrays

    题目: There are two sorted arrays A and B of size m and n respectively. Find the median of the two sor ...

随机推荐

  1. ngrok原理浅析(转载)

    之前在进行 微信Demo开发时曾用到过 ngrok这个强大的tunnel(隧道)工具,ngrok在其github官方页面上的自我诠释是 "introspected tunnels to lo ...

  2. gmpy2安装使用方法

    GMP(GNU Multiple Precision Arithmetic Library,即GNU高精度算术运算库),它是一个开源的高精度运算库,其中不但有普通的整数.实数.浮点数的高精度运算,还有 ...

  3. sqlplus命令手册

    show errorshow allshow usersqlplus show和set命令是两条用于维护SQLPlus系统变量的命令 : SQL> show all --查看所有系统变量值 SQ ...

  4. table常用

    <style> table,table td { border: 1px solid #ccc; border-collapse:collapse; } </style> 注意 ...

  5. HDU 4464 Browsing History(最大ASCII的和)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4464 Problem Description One day when you are going t ...

  6. php使用mysql扩展库链接mysql数据库(查询)

    php链接数据库可以使用mysql扩展库,mysqli,pdo这几种方式,相比java而言要麻烦一点,因为它不像java那么统一.从代码的难易程度来说php的确要简单许多.步骤大体如下 1.打开数据库 ...

  7. 用户向导页面实现左右滑动的ViewPager

    然后在一个博客,以前的博客ImageSwitcher实现用户向导,现在,随着ViewPager实现同样的功能.直接看代码: 布局文件activity_main.xml <RelativeLayo ...

  8. HDU 2149-Public Sale(巴什博奕)

    Public Sale Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit  ...

  9. linux下emacs安装

    1.下载地址:http://ftp.gnu.org/pub/gnu/emacs/ 下载文件:emacs-24.2.tar.gz 步骤: 一.安装依赖文件:  (先进入root:终端中输入 su -) ...

  10. WCF 出现无法理解Soap Action问题?

    在使用wcf部署到asp.net上时,遇到了,“无法理解soap Action 问题,”最简单的解决办法是更换NET framwork 高本版的框架. 不过不更换net framwork 框架,能否解 ...