要求:

右边大数组中包含了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. Netbeans搭建Android环境

    原文:Netbeans搭建Android环境 Netbeans环境的搭建主要依赖于NBAndroid插件,项目地址: http://www.nbandroid.org/p/installation.h ...

  2. flume 日志采集工具

    Flume是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统,Flume支持在日志系统中定制各类数据发送方,用于收集数据:同时,Flume提供对数据进行简单处理,并 ...

  3. Android 匿名共享内存C接口分析

    在Android 匿名共享内存驱动源码分析中详细分析了匿名共享内存在Linux内核空间的实现,虽然内核空间实现了匿名共享内存,但仍然需要在用户空间为用户使用匿名共享内存提供访问接口.Android系统 ...

  4. pkg-config的用法

    pkg-config的用法 pkg-config pkg-config程序是干什么用的?简单的说就是向用户向程序提供相应库的路径.版本号等信息的程序. 譬如说我们运行以下命令:pkg-config  ...

  5. C标准中一些预定义的宏

    C标准中指定了一些预定义的宏,对于编程经常会用到.下面这个表中就是一些常常用到的预定义宏. 宏(双下滑线) 意义 __DATE__ 进行预处理的日期(“Mmm dd yyyy”形式的字符串文字) __ ...

  6. 2.一步一步学c#(二):核心c#

    简单的控制台应用程序. 代码(它有把某条消息写到屏幕上的一个类组成) 编译并运行程序得到结果: 在上面的代码示例中,前几行代码与名称空间有关,名称空间是把相关类组合在一起的方式.namespace关键 ...

  7. jQuery validate api(转)

    官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...

  8. SQL Server使用LIKE运算符进行匹配查询

    在查询的过程中,如果遇到不能明确的指明查询的限定条件时,就会用到LIKE运算符进行模式匹配查询.在查询时可以使用如下几个通配符: %:包含零个或多个字符的任意字符串 —(下划线):任何单个字符 []: ...

  9. If We Were a Child Again

    Description The Problem The first project for the poor student was to make a calculator that can jus ...

  10. Structs

    1.服务端的运行程序 2.Servlet的三个方法 init service:抽象方法 destroy 3.步骤 (1).在web.xml中 <servlet> <servlet-n ...