Skip to content

Commit

Permalink
Update ejercicio4.js
Browse files Browse the repository at this point in the history
This is the correct code for filterNumeric my friend
  • Loading branch information
lotusbaba committed Jan 4, 2016
1 parent 959a0ea commit 284d3cf
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions JavaScriptTutorialArray/js/ejercicio4.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ returns new array which contains only numeric values from arr.
*/

var arr = ["a", 1, "b", 2, 1.5];

function filterNumeric(array) {
var arrayNumeric = [];
for (var i = 0; i < array.length; i++) {
if (!isNaN(array[i]))
arrayNumeric.push(array[i]);
function filterNumeric (arr) {
for (i = 0; i<arr.length; i++) {
if (isNaN(arr[i])) {
arr.splice(i,1);
i--;
}
}
return arrayNumeric;
}

window.addEventListener("load", function() {
console.log("Array: "+arr);
console.log("Array de valores numéricos: "+filterNumeric(arr));
});
filterNumeric(arr);
console.log("Array de valores numéricos: "+arr);
});

0 comments on commit 284d3cf

Please sign in to comment.