initialization
, condition
y final-expression
.
Comenzaremos en i = 10
y haremos un bucle mientras i > 0
. Disminuiremos i
en 2 cada bucle con i -= 2
.
var ourArray = [];
for (var i=10; i > 0; i-=2) {
ourArray.push(i);
}
ourArray
ahora contendrá [10,8,6,4,2]
.
Cambiemos nuestra initialization
y final-expression
para que podamos contar hacia atrás de dos en dos con números impares.
myArray
usando un bucle for
.
for
bucle para esto.
testString: 'assert(code.match(/for\s*\(/g).length > 1, "You should be using a for
loop for this.");'
- text: Deberías estar usando el método de matriz push
.
testString: 'assert(code.match(/myArray.push/), "You should be using the array method push
.");'
- text: ' myArray
debe ser igual a [9,7,5,3,1]
.'
testString: 'assert.deepEqual(myArray, [9,7,5,3,1], "myArray
should equal [9,7,5,3,1]
.");'
```