Skip to content

Commit

Permalink
Add Util.Array.empty()
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocasanova committed Sep 24, 2014
1 parent 7f03a71 commit e3902e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ var Util = require('findhit-util');

Util.Array.each() <- Util.Array.forEach()
Util.Array.map()
Util.Array.empty()

// String utils
// Util.string OR Util.String
Expand Down
11 changes: 11 additions & 0 deletions lib/type/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,15 @@ module.exports = (function ( Util ){
return newArray;
};

$.empty = function ( array ) {

if ( Util.isnt.Array( array ) ) {
throw new TypeError("array must be an array");
}

array.splice( 0, array.length );

return array;
};

});
13 changes: 12 additions & 1 deletion test/type/array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe( "Util", function () {

describe( "array", function () {

describe( "map", function () {
describe( ".map", function () {

it( "get 3rd value of each array on array", function () {
var t, a = [
Expand All @@ -28,6 +28,17 @@ describe( "Util", function () {

});

});

describe( ".empty", function () {

it( "should empty the array", function () {
var array = [ 1, 'foo', 'bar', 'lala', 2 ];

Util.Array.empty( array );

expect( array ).to.have.length( 0 );
});

});

Expand Down

0 comments on commit e3902e9

Please sign in to comment.