change .grab to .at, add unlimited args or numbers or arrays and simplify function call to use values and pick

Former-commit-id: 3deb82ad9f55cd7261453a40bb0f046a5340790d
This commit is contained in:
Dan Heberden
2012-12-18 12:52:44 -08:00
parent 2ae0e9d902
commit c86a16df7f
2 changed files with 28 additions and 28 deletions

View File

@@ -667,23 +667,19 @@
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.grab');
QUnit.module('lodash.at');
(function() {
test('should get items in range', function() {
var result = _.grab(['a', 'b', 1.4, 'c', { 'foo': 'bar' }, 'd'], [0, 2, 4]);
var result = _.at(['a', 'b', 1.4, 'c', { 'foo': 'bar' }, 'd'], [0, 2, 4]);
deepEqual( result, ['a', 1.4, { 'foo': 'bar' } ]);
});
test('should work with an object for `collection`', function() {
var result = _.grab({ 'a': 'apple', 'b': 'ball', 'c': 'count' }, ['a', 'c']);
var result = _.at({ 'a': 'apple', 'b': 'ball', 'c': 'count' }, ['a', 'c']);
deepEqual(result, ['apple', 'count']);
});
test('no list should return an empty array', function() {
deepEqual(_.grab(['a', 'b', 'c']), [] );
});
test('out of range selections should return undefined', function() {
var result = _.grab(['a', 'b', 'c'], [1, 9001]);
deepEqual( result, ['b', undefined]);
deepEqual(_.at(['a', 'b', 'c']), [] );
});
}());