Comparing version 3.1.0 to 3.2.0
36
index.js
@@ -14,3 +14,3 @@ "use strict"; | ||
//Declare | ||
var $this,key,length,Obj,eachBreak; | ||
var $this,key,length,Obj; | ||
@@ -38,2 +38,36 @@ //Our contextual this (for the callback) | ||
returnEach(_f,_returnArg,_falseBreak){ | ||
if(is(_f) !== "function") { | ||
throw new TypeError('argument is not a function'); | ||
} | ||
_falseBreak = (_falseBreak === false ? false : true); | ||
//Declare | ||
var $this,key,length,Obj; | ||
//Our contextual this (for the callback) | ||
$this = this; | ||
//Readibly polyfillian | ||
key = 0; | ||
Obj = Object(this); | ||
length = Obj.length >>> 0; | ||
//Iterate (obviously) | ||
while(key<length){ | ||
let val,cbReturn; | ||
if(key in Obj){ | ||
val = Obj[key]; | ||
cbReturn = _f.call($this,key,val,_returnArg); | ||
if(cbReturn === false && _falseBreak){ | ||
break; | ||
} | ||
_returnArg = cbReturn || _returnArg; | ||
} | ||
key++; | ||
} | ||
return _returnArg; | ||
} | ||
//Truthy/falsy indexOf | ||
@@ -40,0 +74,0 @@ contains(_value){ |
{ | ||
"name": "arc-array", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "An array convenience subclass", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tap test/*.js" | ||
"test": "tap test/*.js --coverage --coverage-report=html" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
@@ -60,3 +60,3 @@ # arc-array [![Build Status](https://travis-ci.org/anyuzer/arc-array.svg?branch=master)](https://travis-ci.org/anyuzer/arc-array) | ||
var items = new ArcArray('a','b','c'); | ||
items.each(function(_value,_index,_array){ | ||
items.each(function(_index,_value,_array){ | ||
if(_value === 'b'){ | ||
@@ -68,3 +68,21 @@ return false; //Return explicit false to break | ||
###ArcArray.contains(val:Mixed) | ||
### .returnEach(callback:Function,referenceVal:Mixed [,falseBreak:Boolean]) | ||
Similar to each, but accepts a second value that is passed in initially, and then potentially passed in on each subsequent iteration. And then eventually returned. | ||
Default behavior still uses a hard `false` return as a break, but this can be disabled optionally by passing in false as the third argument. | ||
```js | ||
//Example of returnEach | ||
var numbers = new ArcArray(1,2,3,4,5,6); | ||
var even = numbers.each(function(_index,_value,_evenArray){ | ||
if(_value%2 === 0){ | ||
_evenArray.push(_value); | ||
} | ||
return _evenArray; | ||
},[]); | ||
//Even contains [2,4,6] | ||
``` | ||
###.contains(val:Mixed) | ||
This is a convenience function for `return ([].indexOf(val) !== -1 ? true : false)` | ||
@@ -71,0 +89,0 @@ ```js |
16415
14
319
137