forked from lodash/lodash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdropWhile.js
67 lines (52 loc) · 1.92 KB
/
dropWhile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import assert from 'assert';
import lodashStable from 'lodash';
import { slice, LARGE_ARRAY_SIZE } from './utils.js';
import dropWhile from '../dropWhile.js';
describe('dropWhile', function() {
var array = [1, 2, 3, 4];
var objects = [
{ 'a': 2, 'b': 2 },
{ 'a': 1, 'b': 1 },
{ 'a': 0, 'b': 0 }
];
it('should drop elements while `predicate` returns truthy', function() {
var actual = dropWhile(array, function(n) {
return n < 3;
});
assert.deepStrictEqual(actual, [3, 4]);
});
it('should provide correct `predicate` arguments', function() {
var args;
dropWhile(array, function() {
args = slice.call(arguments);
});
assert.deepStrictEqual(args, [1, 0, array]);
});
it('should work with `_.matches` shorthands', function() {
assert.deepStrictEqual(dropWhile(objects, { 'b': 2 }), objects.slice(1));
});
it('should work with `_.matchesProperty` shorthands', function() {
assert.deepStrictEqual(dropWhile(objects, ['b', 2]), objects.slice(1));
});
it('should work with `_.property` shorthands', function() {
assert.deepStrictEqual(dropWhile(objects, 'b'), objects.slice(2));
});
it('should work in a lazy sequence', function() {
var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3),
predicate = function(n) { return n < 3; },
expected = dropWhile(array, predicate),
wrapped = _(array).dropWhile(predicate);
assert.deepEqual(wrapped.value(), expected);
assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
assert.strictEqual(wrapped.last(), _.last(expected));
});
it('should work in a lazy sequence with `drop`', function() {
var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3);
var actual = _(array)
.dropWhile(function(n) { return n == 1; })
.drop()
.dropWhile(function(n) { return n == 3; })
.value();
assert.deepEqual(actual, array.slice(3));
});
});