FreeCodeCamp:Return Largest Numbers in Arrays
要求:
右边大数组中包含了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的更多相关文章
- freeCodeCamp:Return Largest Numbers in Arrays
右边大数组中包含了4个小数组,分别找到每个小数组中的最大值,然后把它们串联起来,形成一个新数组. 提示:你可以用for循环来迭代数组,并通过arr[i]的方式来访问数组的每个元素. /*思路 for循 ...
- Return Largest Numbers in Arrays
题目要求 右边大数组中包含了4个小数组,分别找到每个小数组中的最大值,然后把它们串联起来,形成一个新数组. 提示:你可以用for循环来迭代数组,并通过arr[i]的方式来访问数组的每个元素. 答题思路 ...
- FCC JS基础算法题(5):Return Largest Numbers in Arrays(找出多个数组中的最大数)
题目描述: 找出多个数组中的最大数右边大数组中包含了4个小数组,分别找到每个小数组中的最大值,然后把它们串联起来,形成一个新数组.提示:你可以用for循环来迭代数组,并通过arr[i]的方式来访问数组 ...
- Return Largest Numbers in Arrays-freecodecamp算法题目
Return Largest Numbers in Arrays(找出多个数组中的最大数) 要求 大数组中包含了4个小数组,分别找到每个小数组中的最大值,然后把它们串联起来,形成一个新数组. 思路 用 ...
- 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] ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- SQL Server 中同时操作的例子:
在SQL 中同一逻辑阶段的操作是同时发生的. 先有一个例子做为带入: declare @x as int =1;declare @y as int =2;set @x=@y;set @y=@x;sel ...
- Windows Phone 8.1 发送http 网络请求。
在windows phone 8.1 中可以用 HttpClient 类来发送http 请求. 例子: try { Uri uri = new Uri(@"http://api.map.ba ...
- Thml 小插件8 天气插件定制
网址:http://www.tianqi.com/plugin/
- java MemCachedClient遍历memcache中所有的key
在java memcached client documentation中没有提共遍历memcache所有key的方法.但是提供了两个方法statsItems和statsCacheDump,通过sta ...
- POJ 3723 Conscription(并查集建模)
[题目链接] http://poj.org/problem?id=3723 [题目大意] 招募名单上有n个男生和m个女生,招募价格均为10000, 但是某些男女之间存在好感,则招募的时候, 可以降低与 ...
- 图片变灰css3
-webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); -ms-filter: grayscale(100%); -o-filte ...
- 谈如何使用c中的qsort快速排序库函数 按主次关键字正确排序
快排的效率很快,但是我们很少知道如何利用它进行多关键字排序,比如我想对一个数组a[i][0]进行的一个元素进行主关键字排序,又想对a[i][1]进行次关键字排序.那么接下来就是解决这个问题的方法. 学 ...
- Matlab中的取整-floor,ceil,fix,round
FLOOR Round towards minus infinity. FLOOR(X) rounds the elements of X to the nearest integers toward ...
- 【JAVA】导出jar包时,Class files on classpath not found
是因为\META-INF\MANIFEST.MF文件里面配置错误 错误版本 Manifest-Version: 1.0Class-Path: 正确版本 Manifest-Version: 1.0Cla ...
- objective-C学习笔记(十)协议
协议 Protocol 协议是类的合同约定,只描述外部接口,不提供具体实现.所以,协议其实可以写在类的.h文件中,不去实现就可以了. 协议可以包含以下成员: 属性 (编译器不会和普通interface ...