how to find max number in array javascript
function findHighestNumber(nums) {
let inputs = nums.filter((val, i) => nums.indexOf(val) === i)
let max = Math.max(...nums);
let min = Math.min(...nums);
return max + (-min);
}
console.log(difference([1, 7, 18, -1, -2, 9]));const array1 = [1, 3, 2];
console.log(Math.max(...array1));function findHigestNumber(nums) {
let inputs = nums.filter((val, i) => nums.indexOf(val) === i)
let max = inputs.length - 1;
let min = 0;
for(let i = 0; i < inputs.length; i++) {
if(inputs[i] > max) max = inputs[i];
if(inputs[i] < min) min = inputs[i];
}
return max + (-min);
}
console.log(difference([1, 7, 18, -1, -2, 9]));var numbers = [1, 2, 3, 4];
Math.max(...numbers) // 4
Math.min(...numbers) // 1Math.max(10, 20); // 20
Math.max(-10, -20); // -10
Math.max(-10, 20); // 20
Also in JavaScript:
- comment in js
- how to check if a string has only alphabets in javascript
- js maths objects
- javascript increment alphabet
- send info with get request in js
- save action hide element in jquery
- js-cookie
- compare if strings are equal javascript
- js functions inside of objects
- push values to state array class react
- jquery is child of
- test if is undefined javascript
- function in javascript
- constants in js
- Use multiple conditional operators in the checkSign function to check if a number is positive, negative or zero. The function should return "positive", "negative" or "zero".
- how to print elements in an array in javascript
- slider js
- jquery back button event
- Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?
- data-dismiss= modal in jquery
- onchange debounce react
- angular lifecycle hooks
- firebase angular send notification to by tocken
- how to know how many pixels of page be scrolled javascript