Min and max value in array javascript assignment expert

Min & Max Values in Array

given an array myArray of integers, write a JS program to find the maximum and minimum values in the array.

input1

[1,4,2,7,9,3,5]

output1

{min: 1, max: 9}

"use strict";

process.stdin.resume[];

process.stdin.setEncoding["utf-8"];

let inputString = "";

let currentLine = 0;

process.stdin.on["data", [inputStdin] => {

 inputString += inputStdin;

}];

process.stdin.on["end", [_] => {

 inputString = inputString

  .trim[]

  .split["\n"]

  .map[[str] => str.trim[]];

 main[];

}];

function readLine[] {

 return inputString[currentLine++];

}

/* Please do not modify anything above this line */

function findMinAndMaxValuesInArray[arr] {

 /* Write your code here */

}

/* Please do not modify anything below this line */

function main[] {

 let myArray = JSON.parse[readLine[]];

 console.log[findMinAndMaxValuesInArray[myArray]];

}

 Harry  September 3, 2022

Problem Statement:

In, find the first value in JavaScript, we are given an array of numbers, we need to find the smallest number from the array that is divisible by 2 and 3 both.

Code to find the first value in JavaScript:

const numbers = [123, 675, 22, 645, 132, 23, 12, 18]
let newNumbers = []
for [let i = 0; i < numbers.length; i++] {
  if[numbers[i]%2==0 && numbers[i]%3==0]{
    newNumbers.push[numbers[i]]
  }
}
console.log[Math.min[...newNumbers]]

Output:

Also Read:

  • Split the sentence in Python | Assignment Expert
  • String Slicing in JavaScript | Assignment Expert
  • First and Last Digits in Python | Assignment Expert
  • List Indexing in Python | Assignment Expert
  • Date Format in Python | Assignment Expert
  • New Year Countdown in Python | Assignment Expert
  • Add Two Polynomials in Python | Assignment Expert
  • Sum of even numbers in Python | Assignment Expert
  • Evens and Odds in Python | Assignment Expert
  • A Game of Letters in Python | Assignment Expert
  • Sum of non-primes in Python | Assignment Expert
  • Smallest Missing Number in Python | Assignment Expert
  • String Rotation in Python | Assignment Expert
  • Secret Message in Python | Assignment Expert
  • Word Mix in Python | Assignment Expert
  • Single Digit Number in Python | Assignment Expert
  • Shift Numbers in Python | Assignment Expert
  • Weekend in Python | Assignment Expert
  • Shift Numbers in Python | Assignment Expert
  • Temperature Conversion in Python | Assignment Expert
  • Special Characters in Python | Assignment Expert
  • Sum of Prime Numbers in the Input in Python | Assignment Expert
  • Numbers in String-1 in Python | Assignment Expert
  • Replace Elements with Zeros in Python | Assignment Expert
  • Remove Words in Python | Assignment Expert
  • Print Digit 9 in Python | Assignment Expert
  • First Prime Number in Python | Assignment Expert
  • Simple Calculator in Python | Assignment Expert
  • Average of Given Numbers in Python | Assignment Expert
  • Maximum in Python | Assignment Expert

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at Thank you

How to find min and max value in array in JavaScript?

Array.prototype.reduce[] can be used to find the maximum element in a numeric array, by comparing each value:.
const arr = [1, 2, 3]; const max = arr. reduce[[a, b] => Math. max[a, b], -Infinity]; ... .
function getMaxOfArray[numArray] { return Math. max. ... .
const arr = [1, 2, 3]; const max = Math. max[....

How to find min element in array JavaScript?

To find the minimum value present in a given array, we can use the Math. min[] function in JavaScript. This function returns the minimum value present in a given array.

How do you find the highest and lowest numbers in JavaScript?

To get the highest or lowest number from an array in JavaScript, you can use the Math. max[] or the Math. min[] methods then spread the elements from the array to these methods using the spread operator [ ... ]. Both the methods Math.

How do you sum an array in JavaScript?

function sumArray[array] { const ourArray = [1, 4, 0, 9, -3]; let sum = 0; ​ for [let i = 0; i < ourArray. length; i += 1] { ... .
function sumArray[array] { let sum = 0; ​ array. forEach[item => { sum += item; ... .
function sumArray[array] { let sum = 0; ​ /*loop over array and add each item to sum. */ for [const item of array] {.

Chủ Đề