2017-08-16 62 views
2

我有一個JavaScript函數:如何恢復2產生相同的功能

var query1 = {{repair_semestre1}}; 
var query2 = {{repair_semestre2}}; 
var result1 = []; 
var result2 = []; 


for (var i = 0; i < query1.LRU.length; i++) { 
    result1.push(formatName(query1.LRU[i], query1.Client[i], query1.round[i])); 


} 

for (var i = 0; i < query2.LRU.length; i++) { 
    result2.push(formatName(query1.LRU[i], query1.Client[i], query1.round[i])); 


} 

return { 
    result1: result1, 
    result2: result2 
}; 

function formatName(lru, turnover, round) { 
    return "[" + lru + "," + turnover + "," + round + "]"; 
} 

它在result1result2返回相同的數值。 如何恢復result2的值。

你能幫我嗎。 謝謝。

+0

投票取值收爲錯字。 [這解釋了爲什麼](https://stackoverflow.com/a/45717496/2427065) –

回答

4

只是一個錯字,在你的第二個for循環您從QUERY1而不是QUERY2

for (var i = 0; i < query2.LRU.length; i++) { 
    result2.push(formatName(query1.LRU[i], query1.Client[i], query1.round[i]));//original 
result2.push(formatName(query2.LRU[i], query2.Client[i], query2.round[i])); //change to this 
}