2017-04-22 3 views
-1

어떻게 다른 결과를 얻을 수 있습니까?자바 스크립트에서 ++ i와 i + 1의 차이점

유일한 차이점 돕기위한 [++ I] 및 [I + 1]

function adjacentElementsProduct(inputArray) { 
    total = inputArray[0] * inputArray[1]; 

    for (i = 1; i < inputArray.length-1; i++) { 
    mul = inputArray[i] * inputArray[++i]; 
    if (total < mul) 
     total = mul; 
     } 
    return total; 
} 

    function adjacentElementsProduct(inputArray) { 
    total = inputArray[0] * inputArray[1]; 

    for (i = 1; i < inputArray.length-1; i++) { 
    mul = inputArray[i] * inputArray[i+1]; 
    if (total < mul) 
     total = mul; 
     } 
    return total; 
} 

덕분이다.

이 질문은 중복으로 표시되었지만 다른 질문은 i ++에 관한 것이며, 내 문제는 ++ i에 관한 것입니다.

+0

을 확인 i

에 새로운 값을 저장하지 않습니다 예를 들어 함수를 다음과 같이 호출하면 : adjacentElementsProduct ([3, 6, -2, -5, 7, 3]); –

+0

'++ i'는'i + 1'에없는 부작용이 있습니다. 그것은 힌트로 충분해야합니다. – zwol

답변