From 1f7796b0f8fbc7eeead34ec5df495166c822cd8e Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 2 Apr 2012 23:11:56 +0200 Subject: [PATCH] make Ox.reverse() work for arrays --- source/Ox/js/Collection.js | 13 +++++++++++++ source/Ox/js/Format.js | 2 +- source/Ox/js/Geo.js | 6 ++++-- source/Ox/js/String.js | 9 --------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/source/Ox/js/Collection.js b/source/Ox/js/Collection.js index 9dde230a..31d5eb12 100644 --- a/source/Ox/js/Collection.js +++ b/source/Ox/js/Collection.js @@ -516,6 +516,19 @@ Ox.min = function(col) { return Math.min.apply(Math, Ox.values(col)); }; +/*@ +Ox.reverse Reverses an array or string + > Ox.reverse([1, 2, 3]) + [3, 2, 1] + > Ox.reverse('foobar') + 'raboof' +@*/ +Ox.reverse = function(col) { + return Ox.isArray(col) + ? Ox.clone(col).reverse() + : col.toString().split('').reverse().join(''); +}; + /*@ Ox.setPropertyOnce Sets a property once Given a array of objects, each of which has a property with a boolean diff --git a/source/Ox/js/Format.js b/source/Ox/js/Format.js index 50e3c58b..a01fae18 100644 --- a/source/Ox/js/Format.js +++ b/source/Ox/js/Format.js @@ -506,7 +506,7 @@ Ox.formatOrdinal Formats a number as an ordinal @*/ Ox.formatOrdinal = function(num) { var str = num.toString(), - len = str.length + len = str.length, end = str[len - 1], ten = len > 1 && str[len - 2] == '1'; if (end == '1' && !ten) { diff --git a/source/Ox/js/Geo.js b/source/Ox/js/Geo.js index 5ebc6de3..82bfdeb5 100644 --- a/source/Ox/js/Geo.js +++ b/source/Ox/js/Geo.js @@ -246,6 +246,8 @@ > Ox.containsArea(Ox.test.areas[2], Ox.test.areas[3]) true @*/ + // FIXME: Shouldn't this be rewritten as a test + // if the intersection is equal to the inner area? Ox.containsArea = function(areaA, areaB) { // If an area crosses the dateline, // we split it into two parts, @@ -287,9 +289,9 @@ > Ox.intersectAreas([Ox.test.areas[2], Ox.test.areas[3]]) {sw: {lat: 25, lng: -155}, ne: {lat: 30, lng: -150}} @*/ + // FIXME: handle the a corner case where + // two areas have two intersections Ox.intersectAreas = function(areas) { - // FIXME: handle the a corner case where - // two areas have two intersections var intersections, ret; // If an area crosses the dateline, // we split it into two parts, diff --git a/source/Ox/js/String.js b/source/Ox/js/String.js index 68a969a4..c53cdc5c 100644 --- a/source/Ox/js/String.js +++ b/source/Ox/js/String.js @@ -410,15 +410,6 @@ Ox.repeat = function(val, num) { return ret; }; -/*@ -Ox.reverse Reverses a string - > Ox.reverse('foobar') - 'raboof' -@*/ -Ox.reverse = function(str) { - return str.toString().split('').reverse().join(''); -}; - /*@ Ox.startsWith Checks if a string starts with a given substring If the substring is a string literal (and not a variable),