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 ...
随机推荐
- python 推导式和迭代器、生成器
1.常用推导式 推导式是从一个或者多个迭代器快速简洁创建数据结构的一种方法. 1.1 _ 列表推导式 最简单的形式: [exprssion for item in iterable] 示例: nu ...
- 自增或自减例子:i++和++i的相同点和不同点
/* Name:++i和i++的区别 Copyright: By.不懂网络 Author: Yangbin Date:2014年2月15日 02:40:27 Description:熟悉前自增或自减的 ...
- Eclipse启动后一直Initializing Java Tooling (1%)
问题症状: 工作中eclipse崩溃,再次启动后cpu占用99%,状态栏一直显示Initializing Java Tooling: (1%). 解决方案: 删除\workspace\.metadat ...
- SPOJ 7258 Lexicographical Substring Search(后缀自动机)
[题目链接] http://www.spoj.com/problems/SUBLEX/ [题目大意] 给出一个字符串,求其字典序排名第k的子串 [题解] 求出sam上每个节点被经过的次数,然后采用权值 ...
- oracle db_unnqiue_name db_name sid_name instance_name service_name
- Oh, my goddess(bfs)
Oh, my goddess 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Shining Knight is the embodiment of justice ...
- 全面理解js面向对象
前言 当今 JavaScript 大行其道,各种应用对其依赖日深.web 程序员已逐渐习惯使用各种优秀的 JavaScript 框架快速开发 Web 应用,从而忽略了对原生 JavaScript 的学 ...
- Mac系统下下删除加锁文件方法|使用终端命令强制清除废纸篓中的文件
链接地址1:http://jingyan.baidu.com/article/fdffd1f8e39403f3e98ca195.html 在Mac OS X下,无法删除的文件无外乎三种情况:1,文件( ...
- Mongodb PHP开发类库
<?php /** * Mongodb 基本操作API,支持基本类似关系统型数据库的操作接口 * * @version 1.0 * * [说明] * * 1:该版本API实现了 Mongodb ...
- linux用户管理最常用的三个文件说明(不完整版)
涉及到三个文本文件:/etc/passwd /etc/shadow /etc/group 文件相关: /etc/passwd和用户名相关 /etc/shadow和密码相关 /etc/group和用户所 ...