Hackerss.com

Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in
hackerss
hackerss

Posted on

Encontrar el numero mas grande en un arreglo de enteros in Javascript

Encontrar el numero mas grande en un arreglo de enteros - Javascript:


//function to find the largest number in an array
function findLargestNumber(arr) {
  //set the largest number to the first number in the array
  let largestNumber = arr[0];

  //loop through the array
  for (let i = 0; i < arr.length; i++) {
    //if the current number is greater than the largest number
    if (arr[i] > largestNumber) {
      //set the current number as the largest number
      largestNumber = arr[i];
    }
  }

  //return the largest number
  return largestNumber;
}

//example
const result = findLargestNumber([1, 2, 3, 4, 5]);

//output
console.log(result); //5


Enter fullscreen mode Exit fullscreen mode

Top comments (0)