Wie kann das mir andere Ergebnisse geben?Was ist der Unterschied zwischen ++ i und i + 1 in Javascript
Der einzige Unterschied ist die [++ i] und [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;
}
Danke für die Hilfe.
Diese Frage wurde als Duplikat markiert, aber die anderen Fragen beziehen sich auf i ++ und meine bezieht sich auf ++ i.
speichern Zum Beispiel, wenn Sie die Funktion aufrufen mit: beachselectElementsProduct ([3, 6, -2, -5, 7, 3]); –
'++ i' hat eine Nebenwirkung, die' i + 1' nicht hat. Das sollte ein Hinweis sein. – zwol