const arr = [23,42,34,1,5];
      function findMax(){
        let max;
        for(let i=0; i<arr.length; i++){
          for(let j=0; j<arr.length; j++){
            (arr[i]>=arr[j])? (max>arr[i]?max : (max=arr[i])):max;
          }
        }
        return max;
      }
      console.log(findMax());

      Javascript language logo
      Find Max in array

      The code creates an array of four values, [23, 42, 34, 1], and sets up a function to find the maximum value in the array. The function loops through the array, testing to see if the value at position i is greater than the value at position j. If it is, the maximum value is set to be the value at position i plus the value at position j. Otherwise, the maximum value is set to be the value at position i.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.