diff --git a/source/Ox/js/Array.js b/source/Ox/js/Array.js index 7dc073ca..f44315a6 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. @@ -8,7 +8,7 @@ Ox.api Turns an array into a list API items <[o]> An array of objects (key/value stores) options Options object cache If true, cache results - enums Enumerables, for example {size: ['S', 'M', 'L', 'XL']} + enums Enumerables, for example {size: ['S', 'M', 'L']} geo If true, return combined area with totals sort <[o]|[s]> Default sort, for example ['+name', '-age'] sums <[s]> List of keys to be included in totals @@ -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 = { @@ -466,50 +466,50 @@ Ox.range = function() { (function() { - function getSortValues(arr, fn) { - var arr_ = fn ? arr.map(fn) : arr, - len, matches = [], sort = {}; + function getSortValues(array, map) { + var mappedArray = map ? array.map(map) : array, + length, matches = [], sort = {}; // find numbers - arr.forEach(function(val, i) { - var match; - if (Ox.isString(val)) { - match = arr_[i].match(/\d+/g); + array.forEach(function(value, i) { + var match, mappedValue = mappedArray[i]; + if (Ox.isString(mappedValue)) { + match = mappedValue.match(/\d+/g); if (match) { matches = matches.concat(match); } } }); // get length of longest number - len = Ox.max(Ox.map(matches, function(val) { - return val.length; + length = Ox.max(Ox.map(matches, function(value) { + return value.length; })); // make lowercase, remove leading non-word characters, // pad numbers and move leading articles to the end - arr.forEach(function(val, i) { - var val_ = arr_[i]; + array.forEach(function(value, i) { + var mappedValue = mappedArray[i]; if ( - Ox.isEmpty(val_) - || Ox.isNull(val_) - || Ox.isUndefined(val_) + Ox.isEmpty(mappedValue) + || Ox.isNull(mappedValue) + || Ox.isUndefined(mappedValue) ) { - sort[val] = null; - } else if (Ox.isString(val_)) { - sort[val] = val_.toLowerCase() + sort[value] = null; + } else if (Ox.isString(mappedValue)) { + sort[value] = mappedValue.toLowerCase() .replace(/^\W+/, '') .replace(/\d+/g, function(match) { - return Ox.pad(match, len); + return Ox.pad(match, length); }); Ox.forEach(['a', 'an', 'the'], function(article) { - var len; - if (new RegExp('^' + article + ' ').test(sort[val])) { - len = article.length; - sort[val] = sort[val].slice(len + 1) + ', ' - + sort[val].slice(0, len); + var length; + if (new RegExp('^' + article + ' ').test(sort[value])) { + length = article.length; + sort[value] = sort[value].slice(length + 1) + ', ' + + sort[value].slice(0, length); Ox.Break(); } }); } else { - sort[val] = val_; + sort[value] = mappedValue; } }); return sort;