119
rated 0 times
[
125]
[
6]
/ answers: 1 / hits: 7961
/ 10 Years ago, fri, march 14, 2014, 12:00:00
I need to process some arrays that contains undefined
values, like the following:
[ 1, 1, 1, 1, 1, , 1, 1 ]
[ 1, , 1, , , 1, 1 ]
[ 1, , , , , 1, 1 ]
What I need to achieve is not a removal of the undefined
values, but I need to replace them with zeros.
I tried to use underscore.js to achieve this; without success.
The following is my solution attempt:
binarymap = _.map(binarymap, function(curr){
// let's replace all undefined with 0s
if(_.isUndefined(curr)) {
return 0;
}
return curr;
});
Unfortunately, it does not work. underscore.js's function _.map
totally ignores undefined
values.
Any ideas? Elegant solutions?
More From » arrays