-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path_array.js
More file actions
71 lines (58 loc) · 1.36 KB
/
_array.js
File metadata and controls
71 lines (58 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/** @license MIT License (c) copyright 2013 original authors */
/**
* poly common array functions
*
* @author Jared Cacurak
* @author Brian Cavalier
* @author John Hann
*/
(function (define) {
define(function (require) {
var base = require('./_base');
var toObject = base.createCaster(Object, 'Array'),
isFunction = base.isFunction,
undef;
return {
returnValue: returnValue,
iterate: iterate,
toArrayLike: toArrayLike
};
function toArrayLike (o) {
return (base.toString(o) == '[object String]')
? o.split('')
: toObject(o);
}
function returnValue (val) {
return val;
}
function iterate (arr, lambda, continueFunc, context, start, inc) {
var alo, len, i, end;
alo = toArrayLike(arr);
len = alo.length >>> 0;
if (start === undef) start = 0;
if (!inc) inc = 1;
end = inc < 0 ? -1 : len;
if (!isFunction(lambda)) {
throw new TypeError(lambda + ' is not a function');
}
if (start == end) {
return true;
}
if ((start <= end) ^ (inc > 0)) {
throw new TypeError('Invalid length or starting index');
}
for (i = start; i != end; i = i + inc) {
if (i in alo) {
if (!continueFunc(lambda.call(context, alo[i], i, alo), i, alo[i])) {
return false;
}
}
}
return true;
}
});
}(
typeof define == 'function' && define.amd
? define
: function (factory) { module.exports = factory(require); }
));