make Ox.reverse() work for arrays

This commit is contained in:
rolux 2012-04-02 23:11:56 +02:00
parent 1576ba4c48
commit 1f7796b0f8
4 changed files with 18 additions and 12 deletions

View file

@ -516,6 +516,19 @@ Ox.min = function(col) {
return Math.min.apply(Math, Ox.values(col));
};
/*@
Ox.reverse <f> 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 <f> Sets a property once
Given a array of objects, each of which has a property with a boolean

View file

@ -506,7 +506,7 @@ Ox.formatOrdinal <f> 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) {

View file

@ -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}}
@*/
Ox.intersectAreas = function(areas) {
// FIXME: handle the a corner case where
// two areas have two intersections
Ox.intersectAreas = function(areas) {
var intersections, ret;
// If an area crosses the dateline,
// we split it into two parts,

View file

@ -410,15 +410,6 @@ Ox.repeat = function(val, num) {
return ret;
};
/*@
Ox.reverse <f> Reverses a string
> Ox.reverse('foobar')
'raboof'
@*/
Ox.reverse = function(str) {
return str.toString().split('').reverse().join('');
};
/*@
Ox.startsWith <f> Checks if a string starts with a given substring
If the substring is a string literal (and not a variable),