diff --git a/source/Ox/js/Array.js b/source/Ox/js/Array.js index aca78d33..7df97272 100644 --- a/source/Ox/js/Array.js +++ b/source/Ox/js/Array.js @@ -1,6 +1,6 @@ 'use strict'; -/*@ +/* Ox.api Turns an array into a list API Ox.api takes an array and returns a function that allows you to run complex queries against it. See the examples below for details. @@ -113,7 +113,7 @@ Ox.api Turns an array into a list API {positions: {foo: 2, bar: 0}} > Ox.test.apiResults[8].data {items: [{i: 2, size: 'L'}, {i: 1, size: 'M'}]} -@*/ +*/ Ox.api = function(items, options) { var api = { @@ -159,7 +159,9 @@ Ox.api = function(items, options) { // return positions data = {positions: {}}; options.positions.forEach(function(id) { - data.positions[id] = Ox.getIndex(result.data.items, api.unique, id) + data.positions[id] = Ox.indexOf(result.data.items, function(item) { + return item[api.unique] == id; + }); }); result.data = data; } else if (!options.keys) { @@ -356,9 +358,11 @@ Ox.flatten = function(arr) { return ret; }; +/* Ox.indexOf = function(arr) { // indexOf for primitives, test for function, deep equal for others }; +*/ /*@ Ox.merge Merges an array with one or more other arrays @@ -368,13 +372,17 @@ Ox.merge Merges an array with one or more other arrays > Ox.merge(1, [2, 3, 2], 1) [1, 2, 3, 2, 1] @*/ -// FIXME: a1.push.apply(a1, a2) should be much faster Ox.merge = function(arr) { arr = Ox.makeArray(arr); - Ox.forEach(Array.prototype.slice.call(arguments, 1), function(arg) { - Ox.forEach(Ox.makeArray(arg), function(val) { - arr.push(val); - }); + Ox.slice(arguments, 1).forEach(function(arg) { + arg = Ox.makeArray(arg); + if (arg.length < Ox.STACK_SIZE) { + arr.push.apply(arr, arg); + } else { + arg.forEach(function(val) { + arr.push(val); + }); + } }); return arr; };