Finding the minimum sum of an array

Finding the minimum sum of an array


Hi everyone

Having a small issue. I am trying to find the minimum value of an array.

function min(arr) {
  var min = arr[0];
  for(var i= 0; i<arr.length; i++) {
  if(arr[i] < min) {
     min = arr[i];
  return min;
min(([9, 8, 16, 14, 6])); 

This works fine, but when I try to pass in [6, 1, 7, 2, 8] I am still getting 8. Not sure what needs fixing. If anyone has suggestions that would be great


I just ran it in node and got 1 as the answer, so that’s odd.

Could you run it again to check? It looks right to me!


not sure what happened but it’s working now!