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 ...
随机推荐
- 移动端的click
移动端的click 移动端click和touch的关系 搬运 http://segmentfault.com/q/1010000000691822 手指在屏幕上滑动时 各个touch的触发顺序 tou ...
- canvas 基础知识
canvas 基础 低版本的ie不支持html5,需要引入excanvas.js来让ie支持canvas. 检测支持canvas <canvas id="canvas" wi ...
- android小知识之注释模板(转载)
设置注释模板的入口: Window->Preference->Java->Code Style->Code Template 然后展开Comments节点就是所有需设置注释的元 ...
- Uva 1612 Guess
Thinking about it: 题目要求最后一名(也就是第N位)的分数要尽量的大,那么就一定要求第N-1名的分数也要尽量大.假如N-1可以取400和500,那么N-1应该取500,如果取400, ...
- UVA - 10129Play on Words(欧拉路)
UVA - 10129Play on Words Some of the secret doors contain a very interesting word puzzle. The team o ...
- github中的ssh配置
1.配置git信息 设置git的user name和email: $ git config --global user.name "tigerjibo"$ git config - ...
- Java项目打包工具安装失败解决方法
在学习Java的时候我们打包项目但遇到例如以下情况:(提示没有找到java的执行环境! ) 网上眼下有两中的解决方式: (1)选择本地jdk环境; (2)下载Download 可是第一种选择本地老是失 ...
- 日常之学习CSS3变形和js函数指针
1,transform变形属性,包括rotate(xxdeg)旋转,translate(x轴px,y轴px)移动,scale(0.5,2)变形(x轴缩小0.5倍,y轴放大2倍),skew(x轴deg, ...
- Windows配置Python编程环境
1.安装Python https://www.python.org/ 2.修改环境变量 将安装python的路径加到path路径 3.配置notepad++ a. notepad++/运行/“运行”按 ...
- malloc/free和new/delete的区别汇总
一.基本概念 malloc/free 1.函数原型及说明: void* malloc(long NumBytes):该函数分配了NumBytes个字节,并返回了指向这块内存的指针.如果分配失败,则返回 ...