public/js-roguelike-skeleton/src/array-2d.js
function(filter, withCoords){
            withCoords = withCoords || false;
            var output = [];
            for (var x = 0; x < this.width; x++) {
                for (var y = 0; y < this.height; y++) {
                    var val = this.get(x, y);
                    if(filter(val, x, y)){
                        if (withCoords) {
                            output.push({
                                x: x,
                                y: y,
                                value: val
                            });
                        } else {
                            output.push(val);
                        }
                    }
                }
            }
            return output;
        }
function(filter, withCoords){
            withCoords = withCoords || false;
            var output = [];
            for (var x = 0; x < this.width; x++) {
                for (var y = 0; y < this.height; y++) {
                    var val = this.get(x, y);
                    if(filter(val, x, y)){
                        if (withCoords) {
                            output.push({
                                x: x,
                                y: y,
                                value: val
                            });
                        } else {
                            output.push(val);
                        }
                    }
                }
            }
            return output;
        }
function ( filter , withCoords ) { withCoords = withCoords || false ; var output = [ ] ; for ( var x = 0 ; x < this . width ; x ++ ) { for ( var y = 0 ; y < this . height ; y ++ ) { var val = this . get ( x , y ) ; if ( filter ( val , x , y ) ) { if ( withCoords ) { output . push ( { x : x , y : y , value : val } ) ; } else { output . push ( val ) ; } } } } return output ; }
Retrieves an array of the filtered values.
@method filter
@param {Function} filter - A function to determine if a value is to be included in results (returns true). (function(value, x, y){ return true;})
@param {Bool} [withCoords=false] - If true the returned array will include the coords of each value ([{x: 0, y: 0, value: 1}, ...])
@return {Array} An array of coord values matched by the filter function.
Retrieves an array of the filtered values .