Skip to content

Commit

Permalink
Adding filter(fn), fixes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed May 31, 2015
1 parent a1618d7 commit 9ced521
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 10 deletions.
18 changes: 15 additions & 3 deletions lib/haro.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @author Jason Mulligan <jason.mulligan@avoidwork.com>
* @copyright 2015
* @license BSD-3-Clause
* @link https://github.com/avoidwork/haro
* @version 1.0.4
* @link http://avoidwork.github.io/haro
* @version 1.0.5
*/
( function ( global ) {
const Promise = global.Promise || require( "es6-promise" ).Promise;
Expand Down Expand Up @@ -148,6 +148,18 @@ class Haro {
return this.data.entries();
}

filter ( fn ) {
let result = [];

this.forEach( function ( i ) {
if ( fn( i ) === true ) {
result.push( i );
}
} );

return tuple.call( tuple, result );
}

forEach ( fn, ctx ) {
return this.data.forEach( fn, ctx );
}
Expand Down Expand Up @@ -280,7 +292,7 @@ function factory ( data=null, config={} ) {
return new Haro( data, config );
}

factory.version = "1.0.4";
factory.version = "1.0.5";

// Node, AMD & window supported
if ( typeof exports !== "undefined" ) {
Expand Down
19 changes: 16 additions & 3 deletions lib/haro.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @author Jason Mulligan <jason.mulligan@avoidwork.com>
* @copyright 2015
* @license BSD-3-Clause
* @link https://github.com/avoidwork/haro
* @version 1.0.4
* @link http://avoidwork.github.io/haro
* @version 1.0.5
*/
"use strict";

Expand Down Expand Up @@ -168,6 +168,19 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
value: function entries() {
return this.data.entries();
}
}, {
key: "filter",
value: function filter(fn) {
var result = [];

this.forEach(function (i) {
if (fn(i) === true) {
result.push(i);
}
});

return tuple.call(tuple, result);
}
}, {
key: "forEach",
value: function forEach(fn, ctx) {
Expand Down Expand Up @@ -327,7 +340,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
return new Haro(data, config);
}

factory.version = "1.0.4";
factory.version = "1.0.5";

// Node, AMD & window supported
if (typeof exports !== "undefined") {
Expand Down
2 changes: 1 addition & 1 deletion lib/haro.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9ced521

Please sign in to comment.