make Ox.forEach(object...) return a number; remove Ox.setPropertyOnce; move Ox.last to Array.js; update documentation and tests

This commit is contained in:
rolux 2012-06-02 16:08:01 +02:00
commit ecd84770dd
4 changed files with 104 additions and 90 deletions

View file

@ -457,6 +457,33 @@ Ox.indexOf = function(arr) {
};
*/
/*@
Ox.last <f> Gets or sets the last element of an array
Unlike `arrayWithALongName[arrayWithALongName.length - 1]`,
`Ox.last(arrayWithALongName)` is short.
<script>
Ox.test.array = [1, 2, 3];
</script>
> Ox.last(Ox.test.array)
3
> Ox.last(Ox.test.array, 4)
[1, 2, 4]
> Ox.test.array
[1, 2, 4]
> Ox.last('123')
'3'
@*/
Ox.last = function(array, value) {
var ret;
if (arguments.length == 1) {
ret = array[array.length - 1];
} else {
array[array.length - 1] = value;
ret = array;
}
return ret;
};
/*@
Ox.makeArray <f> Wraps any non-array in an array.
(value) -> <a> Array