A list of numbers is passed in to doubled(). It returns a new list with every number times 2. It does not change the list that was passed in.
doubled([1, 5, 8]) returns [2, 10, 16].
8 strips: Q1 to Q8
for (var i = 0; i < list.length; i++) { Q1return result; Q2var result = []; Q3} Q4appendItem(result, list[i] * 2); Q5function doubled(list) { Q6appendItem(list, list[i] * 2); Q7} Q8Order: Q6, Q3, Q1, Q5, Q8, Q2, Q4. Extra: Q7
function doubled(list) {
var result = [];
for (var i = 0; i < list.length; i++) {
appendItem(result, list[i] * 2);
}
return result;
} Extra strip: appendItem(list, list[i] * 2);. This adds to the list the loop is going through. The list keeps getting longer, so the loop never ends.