如何使用三个不同的数据维度计算我的域的范围?请考虑以下数据:
var data = [
{
"Date":"10-10-2013",
"High1" : 3049,
"High2" : 2100,
"high3" : 43
},
{
"Date":"09-10-2013",
"High1" : 3142,
"High2" : 2010,
"high3" : 23
},
{
"Date":"08-10-2013",
"High1" : 3099,
"High2" : 2190,
"high3" : 90
}
Run Code Online (Sandbox Code Playgroud)
我想为High1绘制一条线,为High3绘制另一条线,为High3绘制另一条线,因此需要找到所有组合的范围,以便为图形创建一个y轴.
hello im trying to build this function into my code:
Array.max = function (array) {
return Math.max.apply(Math, array);
};
Array.min = function (array) {
return Math.min.apply(Math, array);
};
Run Code Online (Sandbox Code Playgroud)
as dictated by: JavaScript: min & max Array values?. However when i try to call it using:
console.log(a.max());
Run Code Online (Sandbox Code Playgroud)
where
a = [245, 3, 40, 89, 736, 19, 138, 240, 42]
Run Code Online (Sandbox Code Playgroud)
I get the following Error:
Uncaught TypeError: Object [object Array] has no method 'max'
Run Code Online (Sandbox Code Playgroud)
Can someone help me with this?
您好,我是 angularjs 的新手,这里我需要该数组中最高的五个值,而不是只有一个最大值。我已经尝试过,但我只得到一个最大值。
var arr = [3, 4, 12, 1, 0, 5,22,20,18,30,52];
var max = arr[0];
var maxValues = [];
for (var k = 1; k < arr.length; k++) {
if (arr[k] > max) {
max = arr[k]; // output is 52
//do some thing to push max five values ie 52,30,22,20,18
}
}
console.log("Max is: " + max);
console.log("total five max values is: " + maxValues);expected output[52,30,22,20,18];
Run Code Online (Sandbox Code Playgroud) 我创建了一个整数数组,并想知道它是否有一个或多个负值.
我不想创建一个for()循环并检查数组中的每个元素是正还是负,因为我只想返回一次(例如:我不希望我的函数"返回false;"一百万次) .
我考虑的一个选项是将数组中的每个值乘以其倒数的绝对值,因此我得到一个1或-1的数组(或者如果值为0则未定义)然后我可以将第二个数组中的所有值相加看看它是否等于数组的长度.
但是,这种方法的问题在于它不考虑1/0,而且也很繁琐.我想知道是否有更快的方法来检查数组是否包含至少一个负值.
- 来自初学JavaScript程序员
创建一个名为 bigNumberInArray() 的函数。
这需要一个数组作为参数并返回最大的数字。
这是一个数组
const array = [-1, 0, 3, 100, 99, 2, 99]
Run Code Online (Sandbox Code Playgroud)
我在 JavaScript 代码中尝试的内容:
function biggestNumberInArray(arr) {
for (let i = 0; i < array.length; i++) {
for(let j=1;j<array.length;j++){
for(let k =2;k<array.length;k++){
if(array[i]>array[j] && array[i]>array[k]){
console.log(array[i]);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
它返回 3 100 99。
我只想返回 100,因为它是最大的数字。
有没有更好的方法来使用循环来获得最大的价值?
使用三个不同的 JavaScript 循环来实现这一点(for、forEach、for of、for in)。
您可以使用其中三个来完成它。