2017-01-24 11 views
-1

하위 배열에서 최소 찾기 2 단계에서 멈추었습니다. 프로그램이 정확하다는 것을 확인하기 위해 2 가지 Assert.equal에 대한 값을 찾을 수 없습니다.칸 아카데미 : 부분 배열에서 최소를 찾습니다.

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,?) , ?); 

어떤 도움을 다음과 같이

는 내가 가지고있다?

+0

당신은이 언어에 태그를 달았으며 직접 대답 할 수있는 방식으로 질문에주의를 기울였습니다. 그렇게 해보면 더 많은 도움을 얻을 수 있습니다. 이렇게 할 때이 주석을 쓸모없는 것으로 플래그 할 수 있습니다. –

답변

0

쉽습니다. 메서드 assertEqual은 두 인수가 동일하다는 것을 나타냅니다.

Program.assertEqual(indexOfMinimum(array,1) , 1); 
Program.assertEqual(indexOfMinimum(array,5) , 6);