I'm trying to understand the filter function and have run into a problem with my first test.I'm trying to understand the filter function and have run into a problem with my first test.
Why does the function seem to add 1 to each element of the original array
but returns one less element in the new array?
The commented out test (isButEnough) seems to work as advertised.The commented out test (isButEnough) seems to work as advertised.Code:<!DOCTYPE HTML> <html> <head> <title> Untitled </title> <meta http- <script type="text/javascript"> function addOne(element, index, array) { return (element++); } var Aarr = [0,1,2,3,4,5,6,7,8,9]; var Barr = Aarr.filter(addOne); alert('Orig: \n'+Aarr+'\n\nadd 1: \n'+Barr); /* // From: function isBigEnough(element, index, array) { return (element >= 10); } var filtered = [12, 5, 8, 130, 44].filter(isBigEnough); alert(filtered); // filtered is [12, 130, 44] */ </script> </head> <body> </body> </html>