Array.prototype.map()
, or simply map()
earlier, the map
method returns an array of the same length as the one it was called on. It also doesn't alter the original array, as long as its callback function doesn't.
In other words, map
is a pure function, and its output depends solely on its inputs. Plus, it takes another function as its argument.
-It would teach us a lot about map
to try to implement a version of it that behaves exactly like the Array.prototype.map()
with a for
loop or Array.prototype.forEach()
.
-Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well.
+You might learn a lot about the map
method if you implement your own version of it. It is recommended you use a for
loop or Array.prototype.forEach()
.
Array.prototype.myMap()
, which should behave exactly like Array.prototype.map()
. You may use a for
loop or the forEach
method.
+Write your own Array.prototype.myMap()
, which should behave exactly like Array.prototype.map()
. You should not use the built-in map
method. The Array
instance can be accessed in the myMap
method using this
.
map
method.
testString: assert(!code.match(/\.?[\s\S]*?map/g));
-
```
filter
method if we try to implement a version of it that behaves exactly like Array.prototype.filter()
. It can use either a for
loop or Array.prototype.forEach()
.
-Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well.
+You might learn a lot about the filter
method if you implement your own version of it. It is recommended you use a for
loop or Array.prototype.forEach()
.
Array.prototype.myFilter()
, which should behave exactly like Array.prototype.filter()
. You may use a for
loop or the Array.prototype.forEach()
method.
+Write your own Array.prototype.myFilter()
, which should behave exactly like Array.prototype.filter()
. You should not use the built-in filter
method. The Array
instance can be accessed in the myFilter
method using this
.
filter
method.
testString: assert(!code.match(/\.?[\s\S]*?filter/g));
-
```