Skip to content

Commit

Permalink
Enforce 1 being the minimal chunk size
Browse files Browse the repository at this point in the history
  • Loading branch information
megawac committed Jul 28, 2015
1 parent b221fe7 commit 228689c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 4 additions & 4 deletions test/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,12 @@
test('chunk', function() {
deepEqual(_.chunk([], 2), [], 'chunk for empty array returns an empty array');

deepEqual(_.chunk([1, 2, 3], 0), [1, 2, 3], 'chunk into parts of 0 elements returns original array');
deepEqual(_.chunk([1, 2, 3], 0), [[1], [2], [3]], 'chunk into parts of 0 elements returns array chunked 1');

deepEqual(_.chunk([1, 2, 3], 1), [1, 2, 3], 'chunk into parts of 1 elements returns original array');
deepEqual(_.chunk([1, 2, 3]), [1, 2, 3], 'chunk into parts of 1 elements is default value and returns original array');
deepEqual(_.chunk([1, 2, 3], 1), [[1], [2], [3]], 'chunk into parts of 1 elements returns original array');
deepEqual(_.chunk([1, 2, 3]), [[1], [2], [3]], 'chunk into parts of 1 elements is default value and returns original array');

deepEqual(_.chunk([1, 2, 3], -1), [1, 2, 3], 'chunk into parts of negative amount of elements returns an empty array');
deepEqual(_.chunk([1, 2, 3], -1), [[1], [2], [3]], 'chunk into parts of negative amount of elements returns an empty array');

deepEqual(_.chunk([1, 2, 3], 3), [[1, 2, 3]], 'chunk into parts of current array length elements returns the original array');
deepEqual(_.chunk([1, 2, 3], 5), [[1, 2, 3]], 'chunk into parts of more then current array length elements returns the original array');
Expand Down
3 changes: 1 addition & 2 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,7 @@
// Split an **array** into several arrays containing **count** or less elements
// of initial array
_.chunk = function(array, count) {
count = +count || 1;
if (count <= 1) return slice.call(array);
count = count > 1 ? count : 1;

var result = [];
var i = 0, length = array.length;
Expand Down

0 comments on commit 228689c

Please sign in to comment.