0

I am stuck on step 2 of Find minimum in subarray, I can't find the values for 2 more Assert.equal s to find that the program is accurate.

What I have is as follows:

var indexOfMinimum = function(array, startIndex) {
// Set initial values for minValue and minIndex,
// based on the leftmost entry in the subarray:  
var minValue = array[startIndex];
var minIndex = startIndex;


//Loop over items starting with startIndex, 
//updating minValue and minIndex as needed:
for(var nextIndex = minIndex + 1; nextIndex < array.length  ; nextIndex ++) {
if(array[nextIndex]<minValue) {
    minIndex = nextIndex;
    minValue =array[nextIndex];
}

}

return minIndex;
}; 

var array = [18, 6, 66, 44, 9, 22, 14];  
//  For the test array [18, 6, 66, 44, 9, 22, 14], 
//  the value 9 is the smallest of [..66, 44, 9, 22, 14]
//  Since 9 is at index 4 in the original array, 
var index = indexOfMinimum(array, 2);
//  "index" has value 4
println("The index of the minimum value of the subarray starting at index 2 is " + index + "."  );
Program.assertEqual(index, 4);
Program.assertEqual(indexOfMinimum(array,?) , ?);
Program.assertEqual(indexOfMinimum(array,?) , ?);

Any help?

Hum4n01d
  • 1,312
  • 3
  • 15
  • 30
Brandon Peart
  • 11
  • 1
  • 1
  • You should have tagged this to the language, and more carefully stated your question in a way that is directly answerable. Try doing that, and you might get more help. You can flag this comment as obsolete when you do so. – Russia Must Remove Putin Jan 26 '17 at 17:41

1 Answers1

0

It is easy. The method assertEqual asserts both the arguments are equal.

Program.assertEqual(indexOfMinimum(array,1) , 1);
Program.assertEqual(indexOfMinimum(array,5) , 6);
VHS
  • 9,534
  • 3
  • 19
  • 43