diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/utila/lib/array.js | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/utila/lib/array.js')
| -rw-r--r-- | node_modules/utila/lib/array.js | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/node_modules/utila/lib/array.js b/node_modules/utila/lib/array.js new file mode 100644 index 00000000..3873d3ef --- /dev/null +++ b/node_modules/utila/lib/array.js @@ -0,0 +1,165 @@ +// Generated by CoffeeScript 1.6.3 +var array; + +module.exports = array = { + /* + Tries to turn anything into an array. + */ + + from: function(r) { + return Array.prototype.slice.call(r); + }, + /* + Clone of an array. Properties will be shallow copies. + */ + + simpleClone: function(a) { + return a.slice(0); + }, + shallowEqual: function(a1, a2) { + var i, val, _i, _len; + if (!(Array.isArray(a1) && Array.isArray(a2) && a1.length === a2.length)) { + return false; + } + for (i = _i = 0, _len = a1.length; _i < _len; i = ++_i) { + val = a1[i]; + if (a2[i] !== val) { + return false; + } + } + return true; + }, + pluck: function(a, i) { + var index, value, _i, _len; + if (a.length < 1) { + return a; + } + for (index = _i = 0, _len = a.length; _i < _len; index = ++_i) { + value = a[index]; + if (index > i) { + a[index - 1] = a[index]; + } + } + a.length = a.length - 1; + return a; + }, + pluckItem: function(a, item) { + var index, removed, value, _i, _len; + if (a.length < 1) { + return a; + } + removed = 0; + for (index = _i = 0, _len = a.length; _i < _len; index = ++_i) { + value = a[index]; + if (value === item) { + removed++; + continue; + } + if (removed !== 0) { + a[index - removed] = a[index]; + } + } + if (removed > 0) { + a.length = a.length - removed; + } + return a; + }, + pluckOneItem: function(a, item) { + var index, reached, value, _i, _len; + if (a.length < 1) { + return a; + } + reached = false; + for (index = _i = 0, _len = a.length; _i < _len; index = ++_i) { + value = a[index]; + if (!reached) { + if (value === item) { + reached = true; + continue; + } + } else { + a[index - 1] = a[index]; + } + } + if (reached) { + a.length = a.length - 1; + } + return a; + }, + pluckByCallback: function(a, cb) { + var index, removed, value, _i, _len; + if (a.length < 1) { + return a; + } + removed = 0; + for (index = _i = 0, _len = a.length; _i < _len; index = ++_i) { + value = a[index]; + if (cb(value, index)) { + removed++; + continue; + } + if (removed !== 0) { + a[index - removed] = a[index]; + } + } + if (removed > 0) { + a.length = a.length - removed; + } + return a; + }, + pluckMultiple: function(array, indexesToRemove) { + var i, removedSoFar, _i, _len; + if (array.length < 1) { + return array; + } + removedSoFar = 0; + indexesToRemove.sort(); + for (_i = 0, _len = indexesToRemove.length; _i < _len; _i++) { + i = indexesToRemove[_i]; + this.pluck(array, i - removedSoFar); + removedSoFar++; + } + return array; + }, + injectByCallback: function(a, toInject, shouldInject) { + var i, len, val, valA, valB, _i, _len; + valA = null; + valB = null; + len = a.length; + if (len < 1) { + a.push(toInject); + return a; + } + for (i = _i = 0, _len = a.length; _i < _len; i = ++_i) { + val = a[i]; + valA = valB; + valB = val; + if (shouldInject(valA, valB, toInject)) { + return a.splice(i, 0, toInject); + } + } + a.push(toInject); + return a; + }, + injectInIndex: function(a, index, toInject) { + var i, len, toPut, toPutNext; + len = a.length; + i = index; + if (len < 1) { + a.push(toInject); + return a; + } + toPut = toInject; + toPutNext = null; + for(; i <= len; i++){ + + toPutNext = a[i]; + + a[i] = toPut; + + toPut = toPutNext; + + }; + return null; + } +}; |
