-
Notifications
You must be signed in to change notification settings - Fork 0
/
lodash.js
1008 lines (662 loc) · 29.8 KB
/
lodash.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const _ = require('lodash');
// Array
const chunk = _.chunk(['a', 'b', 'c', 'd'], 2);
console.log(chunk); // => [['a', 'b'], ['c', 'd']]
const compact = _.compact([0, 1, false, 2, '', 3]);
console.log(compact); // => [1, 2, 3]
const concat = _.concat([1], 2, [3], [[4]]);
console.log(concat); // => [1, 2, 3, [4]]
const difference = _.difference([2, 1], [2, 3]);
console.log(difference); // => [1]
const differenceBy = _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
console.log(differenceBy); // => [1.2]
const differenceWith = _.differenceWith([2.1, 1.2], [2.3, 3.4], (a, b) => Math.floor(a) === Math.floor(b));
console.log(differenceWith); // => [1.2]
const drop = _.drop([1, 2, 3]);
console.log(drop); // => [2, 3]
const dropRight = _.dropRight([1, 2, 3]);
console.log(dropRight); // => [1, 2]
const dropRightWhile = _.dropRightWhile([1, 2, 3, 4], n => n > 2);
console.log(dropRightWhile); // => [1, 2]
const dropWhile = _.dropWhile([1, 2, 3, 4], n => n < 3);
console.log(dropWhile); // => [3, 4]
const fill = _.fill([1, 2, 3], 'a');
console.log(fill); // => ['a', 'a', 'a']
const fillWith = _.fill(Array(3), 2);
console.log(fillWith); // => [2, 2, 2]
const findIndex = _.findIndex([1, 2, 3, 4], n => n % 2 === 1);
console.log(findIndex); // => 0
const findLastIndex = _.findLastIndex([1, 2, 3, 4], n => n % 2 === 1);
console.log(findLastIndex); // => 2
const firstHead = _.first([1, 2, 3]);
console.log(firstHead); // => 1
const flatten = _.flatten([1, [2, [3, [4]], 5]]);
console.log(flatten); // => [1, 2, [3, [4]], 5]
const flattenDeep = _.flattenDeep([1, [2, [3, [4]], 5]]);
console.log(flattenDeep); // => [1, 2, 3, 4, 5]
const flattenDepth = _.flattenDepth([1, [2, [3, [4]], 5]], 2);
console.log(flattenDepth); // => [1, 2, 3, [4], 5]
const fromPairs = _.fromPairs([['a', 1], ['b', 2]]);
console.log(fromPairs); // => { 'a': 1, 'b': 2 }
const head = _.head([1, 2, 3]);
console.log(head); // => 1
const indexOf = _.indexOf([1, 2, 1, 2], 2);
console.log(indexOf); // => 1
const initial = _.initial([1, 2, 3]);
console.log(initial); // => [1, 2]
const intersection = _.intersection([2, 1], [2, 3]);
console.log(intersection); // => [2]
const intersectionBy = _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
console.log(intersectionBy); // => [2.1]
const intersectionWith = _.intersectionWith([2.1, 1.2], [2.3, 3.4], (a, b) => Math.floor(a) === Math.floor(b));
console.log(intersectionWith); // => [2.1]
const join = _.join(['a', 'b', 'c'], '~');
console.log(join); // => 'a~b~c'
const last = _.last([1, 2, 3]);
console.log(last); // => 3
const lastIndexOf = _.lastIndexOf([1, 2, 1, 2], 2);
console.log(lastIndexOf); // => 3
const nth = _.nth(['a', 'b', 'c', 'd'], 1);
console.log(nth); // => 'b'
const pull = _.pull(['a', 'b', 'c', 'a', 'b', 'c'], 'a', 'c');
console.log(pull); // => ['b', 'b']
const pullAll = _.pullAll(['a', 'b', 'c', 'a', 'b', 'c'], ['a', 'c']);
console.log(pullAll); // => ['b', 'b']
const pullAllBy = _.pullAllBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }], [{ 'x': 1 }, { 'x': 3 }], 'x');
console.log(pullAllBy); // => [{ 'x': 2 }]
const pullAllWith = _.pullAllWith([{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }], [{ 'x': 3, 'y': 4 }], _.isEqual);
console.log(pullAllWith); // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
const pullAt = _.pullAt(['a', 'b', 'c', 'd'], [1, 3]);
console.log(pullAt); // => ['b', 'd']
const remove = _.remove([1, 2, 3, 4], n => n % 2 === 0);
console.log(remove); // => [2, 4]
const reverse = _.reverse([1, 2, 3]);
console.log(reverse); // => [3, 2, 1]
const slice = _.slice([1, 2, 3, 4], 2, 4);
console.log(slice); // => [3, 4]
const sortedIndex = _.sortedIndex([30, 50], 40);
console.log(sortedIndex); // => 1
const sortedIndexBy = _.sortedIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, o => o.x);
console.log(sortedIndexBy); // => 0
const sortedIndexOf = _.sortedIndexOf([4, 5, 5, 5, 6], 5);
console.log(sortedIndexOf); // => 1
const sortedLastIndex = _.sortedLastIndex([4, 5, 5, 5, 6], 5);
console.log(sortedLastIndex); // => 4
const sortedLastIndexBy = _.sortedLastIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, o => o.x);
console.log(sortedLastIndexBy); // => 1
const sortedLastIndexOf = _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
console.log(sortedLastIndexOf); // => 3
const sortedUniq = _.sortedUniq([1, 1, 2]);
console.log(sortedUniq); // => [1, 2]
const sortedUniqBy = _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
console.log(sortedUniqBy); // => [1.1, 2.3]
const tail = _.tail([1, 2, 3]);
console.log(tail); // => [2, 3]
const take = _.take([1, 2, 3]);
console.log(take); // => [1]
const takeRight = _.takeRight([1, 2, 3]);
console.log(takeRight); // => [3]
const takeRightWhile = _.takeRightWhile([1, 2, 3], n => n > 1);
console.log(takeRightWhile); // => [2, 3]
const takeWhile = _.takeWhile([1, 2, 3], n => n < 3);
console.log(takeWhile); // => [1, 2]
const union = _.union([2], [1, 2]);
console.log(union); // => [2, 1]
const unionBy = _.unionBy([2.1], [1.2, 2.3], Math.floor);
console.log(unionBy); // => [2.1, 1.2]
const unionWith = _.unionWith([2.1], [1.2, 2.3], (a, b) => Math.floor(a) === Math.floor(b));
console.log(unionWith); // => [2.1, 1.2]
const uniq = _.uniq([2, 1, 2]);
console.log(uniq); // => [2, 1]
const uniqBy = _.uniqBy([2.1, 1.2, 2.3], Math.floor);
console.log(uniqBy); // => [2.1, 1.2]
const uniqWith = _.uniqWith([2.1, 1.2, 2.3], (a, b) => Math.floor(a) === Math.floor(b));
console.log(uniqWith); // => [2.1, 1.2]
const unzip = _.unzip([['a', 1, true], ['b', 2, false]]);
console.log(unzip); // => [['a', 'b'], [1, 2], [true, false]]
const unzipWith = _.unzipWith([[1, 10, 100], [2, 20, 200]], (...arrays) => _.sum(arrays));
console.log(unzipWith); // => [3, 30, 300]
const without = _.without([2, 1, 2, 3], 1, 2);
console.log(without); // => [3]
const xor = _.xor([2, 1], [2, 3]);
console.log(xor); // => [1, 3]
const xorBy = _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
console.log(xorBy); // => [1.2, 3.4]
const xorWith = _.xorWith([2.1, 1.2], [2.3, 3.4], (a, b) => Math.floor(a) === Math.floor(b));
console.log(xorWith); // => [1.2, 3.4]
const zip = _.zip(['a', 'b'], [1, 2], [true, false]);
console.log(zip); // => [['a', 1, true], ['b', 2, false]]
const zipObject = _.zipObject(['a', 'b'], [1, 2]);
console.log(zipObject); // => { 'a': 1, 'b': 2 }
const zipObjectDeep = _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
console.log(zipObjectDeep); // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
const zipWith = _.zipWith([1, 2], [10, 20], [100, 200], (a, b, c) => a + b + c);
console.log(zipWith); // => [111, 222]
// Collection
const countBy = _.countBy([6.1, 4.2, 6.3], Math.floor);
console.log(countBy); // => { '4': 1, '6': 2 }
const each = _.each([1, 2], value => console.log(value));
const eachRight = _.eachRight([1, 2], value => console.log(value));
const every = _.every([true, 1, null, 'yes'], Boolean);
console.log(every); // => false
const filter = _.filter([4, 5, 6], n => n % 2 == 0);
console.log(filter); // => [4, 6]
const find = _.find([4, 5, 6], n => n % 2 == 0);
console.log(find); // => 4
const findLast = _.findLast([4, 5, 6], n => n % 2 == 0);
console.log(findLast); // => 6
const flatMap = _.flatMap([1, 2], n => [n, n]);
console.log(flatMap); // => [1, 1, 2, 2]
const flatMapDeep = _.flatMapDeep([1, 2], n => [[n, n]]);
console.log(flatMapDeep); // => [1, 1, 2, 2]
const flatMapDepth = _.flatMapDepth([1, 2], (n) => [[[n, n]]], 2);
console.log(flatMapDepth); // => [1, 1, 2, 2]
const forEach = _.forEach([1, 2], value => console.log(value));
const forEachRight = _.forEachRight([1, 2], value => console.log(value));
const groupBy = _.groupBy([6.1, 4.2, 6.3], Math.floor);
console.log(groupBy); // => { '4': [4.2], '6': [6.1, 6.3] }
const includes = _.includes([1, 2, 3], 1);
console.log(includes); // => true
const invokeMap = _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
console.log(invokeMap); // => [[1, 5, 7], [1, 2, 3]]
const keyBy = _.keyBy([{ 'dir': 'left', 'code': 97 }, { 'dir': 'right', 'code': 100 }], object => String.fromCharCode(object.code));
console.log(keyBy); // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
const map = _.map([4, 8], n => n * n);
console.log(map); // => [16, 64]
const orderBy = _.orderBy(['a', 'b', 'c'], ['c', 'a'], ['desc', 'asc']);
console.log(orderBy); // => ['c', 'a', 'b']
const partition = _.partition([1, 2, 3], n => n % 2);
console.log(partition); // => [[1, 3], [2]]
const reduce = _.reduce([1, 2], (sum, n) => sum + n, 0);
console.log(reduce); // => 3
const reduceRight = _.reduceRight([1, 2], (sum, n) => sum + n, 0);
console.log(reduceRight); // => 3
const reject = _.reject([4, 5, 6], n => n % 2 == 0);
console.log(reject); // => [5]
const sample = _.sample([1, 2, 3, 4]);
console.log(sample); // => 2
const sampleSize = _.sampleSize([1, 2, 3, 4], 2);
console.log(sampleSize); // => [3, 1]
const shuffle = _.shuffle([1, 2, 3, 4]);
console.log(shuffle); // => [4, 1, 3, 2]
const size = _.size([1, 2, 3]);
console.log(size); // => 3
const some = _.some([null, 0, 'yes', false], Boolean);
console.log(some); // => true
const sortBy = _.sortBy([1, 2, 3], n => Math.sin(n));
console.log(sortBy); // => [3, 1, 2]
// Date
const now = _.now();
console.log(now); // => 1490719810000
// Function
const after = _.after(2, () => console.log('hello'));
after();
const ary = _.ary(Math.max, 1);
console.log(ary(1, 2, 3)); // => 1
const before = _.before(2, () => console.log('hello'));
before();
const bind = _.bind(console.log, console, 'hello');
bind(); // => 'hello'
const bindKey = _.bindKey(console, 'log', 'hello');
bindKey(); // => 'hello'
const curry = _.curry((a, b, c) => a + b + c);
console.log(curry(1)(2)(3)); // => 6
const curryRight = _.curryRight((a, b, c) => a + b + c);
console.log(curryRight(3)(2)(1)); // => 6
const debounce = _.debounce(() => console.log('hello'), 100);
debounce();
const defer = _.defer(() => console.log('hello'));
defer();
const delay = _.delay(() => console.log('hello'), 100);
delay();
const flip = _.flip((a, b, c) => [a, b, c]);
console.log(flip(1, 2, 3)); // => [2, 1, 3]
const memoize = _.memoize((a, b) => a + b);
console.log(memoize(1, 2)); // => 3
const negate = _.negate(n => n > 0);
console.log(negate(1)); // => false
const once = _.once(() => console.log('hello'));
once();
const overArgs = _.overArgs((x, y) => [x, y], [n => n + 1, n => n + 2]);
console.log(overArgs(1, 2)); // => [2, 4]
const partial = _.partial((a, b, c) => a + b + c, 1, 2);
console.log(partial(3)); // => 6
const partialRight = _.partialRight((a, b, c) => a + b + c, 1, 2);
console.log(partialRight(3)); // => 6
const rearg = _.rearg((a, b, c) => [a, b, c], [2, 0, 1]);
console.log(rearg(1, 2, 3)); // => [3, 1, 2]
const rest = _.rest((a, b, ...c) => [a, b, c]);
console.log(rest(1, 2, 3, 4)); // => [1, 2, [3, 4]]
const spread = _.spread((a, b, c) => a + b + c);
console.log(spread([1, 2, 3])); // => 6
const throttle = _.throttle(() => console.log('hello'), 100);
throttle();
const unary = _.unary(n => n + 1);
console.log(unary(1, 2)); // => 2
const wrap = _.wrap(n => n + 1, n => n * 2);
console.log(wrap(1)); // => 4
// Lang
const castArray = _.castArray(1);
console.log(castArray); // => [1]
const clone = _.clone({ 'a': 1 });
console.log(clone); // => { 'a': 1 }
const cloneDeep = _.cloneDeep({ 'a': 1 });
console.log(cloneDeep); // => { 'a': 1 }
const cloneDeepWith = _.cloneDeepWith({ 'a': 1 }, value => value === 1 ? 2 : value);
console.log(cloneDeepWith); // => { 'a': 2 }
const cloneWith = _.cloneWith({ 'a': 1 }, value => value === 1 ? 2 : value);
console.log(cloneWith); // => { 'a': 2 }
const conformsTo = _.conformsTo({ 'a': 1 }, { 'a': n => n === 1 });
console.log(conformsTo); // => true
const eq = _.eq(1, 1);
console.log(eq); // => true
const gt = _.gt(3, 1);
console.log(gt); // => true
const gte = _.gte(3, 3);
console.log(gte); // => true
const isArguments = _.isArguments(() => {});
console.log(isArguments); // => false
const isArray = _.isArray([1, 2, 3]);
console.log(isArray); // => true
const isArrayBuffer = _.isArrayBuffer(new ArrayBuffer(2));
console.log(isArrayBuffer); // => true
const isArrayLike = _.isArrayLike([1, 2, 3]);
console.log(isArrayLike); // => true
const isArrayLikeObject = _.isArrayLikeObject([1, 2, 3]);
console.log(isArrayLikeObject); // => true
const isBoolean = _.isBoolean(false);
console.log(isBoolean); // => true
const isBuffer = _.isBuffer(new Buffer(2));
console.log(isBuffer); // => true
const isDate = _.isDate(new Date);
console.log(isDate); // => true
const isElement = _.isElement(document.body);
console.log(isElement); // => true
const isEmpty = _.isEmpty({});
console.log(isEmpty); // => true
const isEqual = _.isEqual({ 'a': 1 }, { 'a': 1 });
console.log(isEqual); // => true
const isEqualWith = _.isEqualWith({ 'a': 1 }, { 'a': 1 }, (a, b) => a === b);
console.log(isEqualWith); // => true
const isError = _.isError(new Error);
console.log(isError); // => true
const isFinite = _.isFinite(1);
console.log(isFinite); // => true
const isFunction = _.isFunction(() => {});
console.log(isFunction); // => true
const isInteger = _.isInteger(1);
console.log(isInteger); // => true
const isLength = _.isLength(3);
console.log(isLength); // => true
const isMap = _.isMap(new Map);
console.log(isMap); // => true
const isMatch = _.isMatch({ 'a': 1 }, { 'a': 1 });
console.log(isMatch); // => true
const isMatchWith = _.isMatchWith({ 'a': 1 }, { 'a': 1 }, (a, b) => a === b);
console.log(isMatchWith); // => true
const isNaN = _.isNaN(NaN);
console.log(isNaN); // => true
const isNative = _.isNative(Array.prototype.push);
console.log(isNative); // => true
const isNil = _.isNil(null);
console.log(isNil); // => true
const isNull = _.isNull(null);
console.log(isNull); // => true
const isNumber = _.isNumber(1);
console.log(isNumber); // => true
const isObject = _.isObject({});
console.log(isObject); // => true
const isObjectLike = _.isObjectLike({});
console.log(isObjectLike); // => true
const isPlainObject = _.isPlainObject({});
console.log(isPlainObject); // => true
const isRegExp = _.isRegExp(/abc/);
console.log(isRegExp); // => true
const isSafeInteger = _.isSafeInteger(1);
console.log(isSafeInteger); // => true
const isSet = _.isSet(new Set);
console.log(isSet); // => true
const isString = _.isString('abc');
console.log(isString); // => true
const isSymbol = _.isSymbol(Symbol.iterator);
console.log(isSymbol); // => true
const isTypedArray = _.isTypedArray(new Uint8Array);
console.log(isTypedArray); // => true
const isUndefined = _.isUndefined(undefined);
console.log(isUndefined); // => true
const isWeakMap = _.isWeakMap(new WeakMap);
console.log(isWeakMap); // => true
const isWeakSet = _.isWeakSet(new WeakSet);
console.log(isWeakSet); // => true
const lt = _.lt(1, 3);
console.log(lt); // => true
const lte = _.lte(1, 1);
console.log(lte); // => true
const toArray = _.toArray({ 'a': 1, 'b': 2 });
console.log(toArray); // => [1, 2]
const toFinite = _.toFinite(3.2);
console.log(toFinite); // => 3.2
const toInteger = _.toInteger(3.2);
console.log(toInteger); // => 3
const toLength = _.toLength(3.2);
console.log(toLength); // => 3
const toNumber = _.toNumber('3.2');
console.log(toNumber); // => 3.2
const toPlainObject = _.toPlainObject([1, 2, 3]);
console.log(toPlainObject); // => { '0': 1, '1': 2, '2': 3 }
const toSafeInteger = _.toSafeInteger(3.2);
console.log(toSafeInteger); // => 3
const toString = _.toString(null);
console.log(toString); // => 'null'
// Math
const add = _.add(6, 4);
console.log(add); // => 10
const ceil = _.ceil(4.006);
console.log(ceil); // => 5
const divide = _.divide(6, 4);
console.log(divide); // => 1.5
const floor = _.floor(4.006);
console.log(floor); // => 4
const max = _.max([4, 2, 8, 6]);
console.log(max); // => 8
const maxBy = _.maxBy([{ 'n': 1 }, { 'n': 2 }], o => o.n);
console.log(maxBy); // => { 'n': 2 }
const mean = _.mean([4, 2, 8, 6]);
console.log(mean); // => 5
const meanBy = _.meanBy([{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }], o => o.n);
console.log(meanBy); // => 5
const min = _.min([4, 2, 8, 6]);
console.log(min); // => 2
const minBy = _.minBy([{ 'n': 1 }, { 'n': 2 }], o => o.n);
console.log(minBy); // => { 'n': 1 }
const multiply = _.multiply(6, 4);
console.log(multiply); // => 24
const round = _.round(4.006);
console.log(round); // => 4
const subtract = _.subtract(6, 4);
console.log(subtract); // => 2
const sum = _.sum([4, 2, 8, 6]);
console.log(sum); // => 20
const sumBy = _.sumBy([{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }], o => o.n);
console.log(sumBy); // => 20
// Number
const clamp = _.clamp(-10, -5, 5);
console.log(clamp); // => -5
const inRange = _.inRange(3, 2, 4);
console.log(inRange); // => true
const random = _.random(0, 5);
console.log(random); // => 4
// Object
const assign = _.assign({ 'a': 1 }, { 'b': 2 }, { 'c': 3 });
console.log(assign); // => { 'a': 1, 'b': 2, 'c': 3 }
const assignIn = _.assignIn({ 'a': 1 }, { 'b': 2 }, { 'c': 3 });
console.log(assignIn); // => { 'a': 1, 'b': 2, 'c': 3 }
const assignInWith = _.assignInWith({ 'a': 1 }, { 'b': 2 }, { 'c': 3 }, (a, b) => a + b);
console.log(assignInWith); // => { 'a': 1, 'b': 2, 'c': 3 }
const assignWith = _.assignWith({ 'a': 1 }, { 'b': 2 }, { 'c': 3 }, (a, b) => a + b);
console.log(assignWith); // => { 'a': 1, 'b': 2, 'c': 3 }
const at = _.at({ 'a': [{ 'b': { 'c': 3 } }, 4] }, ['a[0].b.c', 'a[1]']);
console.log(at); // => [3, 4]
const create = _.create({ 'a': 1 }, { 'b': 2 });
console.log(create); // => { 'a': 1, 'b': 2 }
const defaults = _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
console.log(defaults); // => { 'a': 1, 'b': 2 }
const defaultsDeep = _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
console.log(defaultsDeep); // => { 'a': { 'b': 2, 'c': 3 } }
const entries = _.entries({ 'a': 1, 'b': 2 });
console.log(entries); // => [['a', 1], ['b', 2]]
const entriesIn = _.entriesIn({ 'a': 1, 'b': 2 });
console.log(entriesIn); // => [['a', 1], ['b', 2]]
const extend = _.extend({ 'a': 1 }, { 'b': 2 }, { 'c': 3 });
console.log(extend); // => { 'a': 1, 'b': 2, 'c': 3 }
const extendWith = _.extendWith({ 'a': 1 }, { 'b': 2 }, { 'c': 3 }, (a, b) => a + b);
console.log(extendWith); // => { 'a': 1, 'b': 2, 'c': 3 }
const findKey = _.findKey({ 'a': 1, 'b': 2, 'c': 3 }, o => o === 2);
console.log(findKey); // => 'b'
const findLastKey = _.findLastKey({ 'a': 1, 'b': 2, 'c': 3 }, o => o === 2);
console.log(findLastKey); // => 'b'
const forIn = _.forIn({ 'a': 1, 'b': 2 }, (value, key) => console.log(key));
// => Logs 'a' then 'b'.
const forInRight = _.forInRight({ 'a': 1, 'b': 2 }, (value, key) => console.log(key));
// => Logs 'b' then 'a'.
const forOwn = _.forOwn({ 'a': 1, 'b': 2 }, (value, key) => console.log(key));
// => Logs 'a' then 'b'.
const forOwnRight = _.forOwnRight({ 'a': 1, 'b': 2 }, (value, key) => console.log(key));
// => Logs 'b' then 'a'.
const functions = _.functions(_);
console.log(functions); // => ['add', 'after', 'ary', 'assign', ...]
const functionsIn = _.functionsIn(_);
console.log(functionsIn); // => ['add', 'after', 'ary', 'assign', ...]
const get = _.get({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c');
console.log(get); // => 3
const has = _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b');
console.log(has); // => true
const hasIn = _.hasIn({ 'a': 1, 'b': 2, 'c': 3 }, 'b');
console.log(hasIn); // => true
const invert = _.invert({ 'a': 1, 'b': 2, 'c': 1 });
console.log(invert); // => { '1': 'c', '2': 'b' }
const invertBy = _.invertBy({ 'a': 1, 'b': 2, 'c': 1 });
console.log(invertBy); // => { '1': ['a', 'c'], '2': ['b'] }
const invoke = _.invoke({ 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] }, 'a[0].b.c.slice', 1, 3);
console.log(invoke); // => [2, 3]
const keys = _.keys({ 'a': 1, 'b': 2 });
console.log(keys); // => ['a', 'b']
const keysIn = _.keysIn({ 'a': 1, 'b': 2 });
console.log(keysIn); // => ['a', 'b']
const mapKeys = _.mapKeys({ 'a': 1, 'b': 2 }, (value, key) => key + value);
console.log(mapKeys); // => { 'a1': 1, 'b2': 2 }
const mapValues = _.mapValues({ 'a': 1, 'b': 2 }, (value, key) => key + value);
console.log(mapValues); // => { 'a': 'a1', 'b': 'b2' }
const merge = _.merge({ 'a': [{ 'b': 1 }, { 'd': 2 }] }, { 'a': [{ 'c': 3 }, { 'e': 4 }] });
console.log(merge); // => { 'a': [{ 'b': 1, 'c': 3 }, { 'd': 2, 'e': 4 }] }
const mergeWith = _.mergeWith({ 'a': [{ 'b': 1 }, { 'd': 2 }] }, { 'a': [{ 'c': 3 }, { 'e': 4 }] }, (a, b) => a + b);
console.log(mergeWith); // => { 'a': [{ 'b': 1, 'c': 3 }, { 'd': 2, 'e': 4 }] }
const omit = _.omit({ 'a': 1, 'b': '2', 'c': 3 }, ['a', 'c']);
console.log(omit); // => { 'b': '2' }
const omitBy = _.omitBy({ 'a': 1, 'b': '2', 'c': 3 }, _.isNumber);
console.log(omitBy); // => { 'b': '2' }
const pick = _.pick({ 'a': 1, 'b': '2', 'c': 3 }, ['a', 'c']);
console.log(pick); // => { 'a': 1, 'c': 3 }
const pickBy = _.pickBy({ 'a': 1, 'b': '2', 'c': 3 }, _.isNumber);
console.log(pickBy); // => { 'a': 1, 'c': 3 }
const result = _.result({ 'a': { 'b': () => 2 } }, 'a.b');
console.log(result); // => 2
const set = _.set({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c', 4);
console.log(set); // => { 'a': [{ 'b': { 'c': 4 } }] }
const setWith = _.setWith({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c', 4, Object);
console.log(setWith); // => { 'a': [{ 'b': { 'c': 4 } }] }
const toPairs = _.toPairs({ 'a': 1, 'b': 2 });
console.log(toPairs); // => [['a', 1], ['b', 2]]
const toPairsIn = _.toPairsIn({ 'a': 1, 'b': 2 });
console.log(toPairsIn); // => [['a', 1], ['b', 2]]
const transform = _.transform({ 'a': 1, 'b': 2, 'c': 1 }, (result, value, key) => {
(result[value] || (result[value] = [])).push(key);
}, {});
console.log(transform); // => { '1': ['a', 'c'], '2': ['b'] }
const unset = _.unset({ 'a': [{ 'b': { 'c': 7 } }] }, 'a[0].b.c');
console.log(unset); // => true
const update = _.update({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c', n => n * n);
console.log(update); // => { 'a': [{ 'b': { 'c': 9 } }] }
const updateWith = _.updateWith({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c', n => n * n, Object);
console.log(updateWith); // => { 'a': [{ 'b': { 'c': 9 } }] }
const values = _.values({ 'a': 1, 'b': 2, 'c': 3 });
console.log(values); // => [1, 2, 3]
const valuesIn = _.valuesIn({ 'a': 1, 'b': 2, 'c': 3 });
console.log(valuesIn); // => [1, 2, 3]
// Seq
const chain = _.chain([1, 2, 3, 4])
.filter(n => n % 2 == 0)
.map(n => n * n)
.value();
console.log(chain); // => [4, 16]
const tap = _.tap([1, 2, 3], array => console.log(array));
console.log(tap); // => [1, 2, 3]
const thru = _.thru([1, 2, 3], array => array.slice(1, 2));
console.log(thru); // => [2]
const prototypeIterator = _.prototype[Symbol.iterator];
console.log(prototypeIterator); // => [Function: wrapperValue]
const prototypeAt = _.prototype.at;
console.log(prototypeAt); // => [Function: wrapperAt]
const prototypeChain = _.prototype.chain;
console.log(prototypeChain); // => [Function: wrapperChain]
const prototypeCommit = _.prototype.commit;
console.log(prototypeCommit); // => [Function: wrapperCommit]
const prototypeNext = _.prototype.next;
console.log(prototypeNext); // => [Function: wrapperNext]
const prototypePlant = _.prototype.plant;
console.log(prototypePlant); // => [Function: wrapperPlant]
const prototypeReverse = _.prototype.reverse;
console.log(prototypeReverse); // => [Function: wrapperReverse]
const prototypeToJSON = _.prototype.toJSON;
console.log(prototypeToJSON); // => [Function: wrapperValue]
const prototypeValue = _.prototype.value;
console.log(prototypeValue); // => [Function: wrapperValue]
const prototypeValueOf = _.prototype.valueOf;
console.log(prototypeValueOf); // => [Function: wrapperValue]
// String
const camelCase = _.camelCase('--foo-bar--');
console.log(camelCase); // => 'fooBar'
const capitalize = _.capitalize('FRED');
console.log(capitalize); // => 'Fred'
const deburr = _.deburr('déjà vu');
console.log(deburr); // => 'deja vu'
const endsWith = _.endsWith('abc', 'c');
console.log(endsWith); // => true
const escape = _.escape('fred, barney, & pebbles');
console.log(escape); // => 'fred, barney, & pebbles'
const escapeRegExp = _.escapeRegExp('[lodash](https://lodash.com/)');
console.log(escapeRegExp); // => '\[lodash\]\(https://lodash\.com/\)'
const kebabCase = _.kebabCase('Foo Bar');
console.log(kebabCase); // => 'foo-bar'
const lowerCase = _.lowerCase('--Foo-Bar--');
console.log(lowerCase); // => 'foo bar'
const lowerFirst = _.lowerFirst('Fred');
console.log(lowerFirst); // => 'fred'
const pad = _.pad('abc', 8);
console.log(pad); // => ' abc '
const padEnd = _.padEnd('abc', 6, '_-');
console.log(padEnd); // => 'abc_-_'
const padStart = _.padStart('abc', 6, '_-');
console.log(padStart); // => '_-abc'
const parseInt = _.parseInt('08');
console.log(parseInt); // => 8
const repeat = _.repeat('*', 3);
console.log(repeat); // => '***'
const replace = _.replace('Hi Fred', 'Fred', 'Barney');
console.log(replace); // => 'Hi Barney'
const snakeCase = _.snakeCase('Foo Bar');
console.log(snakeCase); // => 'foo_bar'
const split = _.split('a-b-c', '-', 2);
console.log(split); // => ['a', 'b']
const startCase = _.startCase('--foo-bar--');
console.log(startCase); // => 'Foo Bar'
const startsWith = _.startsWith('abc', 'a');
console.log(startsWith); // => true
const template = _.template('hello <%= user %>!');
console.log(template({ 'user': 'fred' })); // => 'hello fred!'
const toLower = _.toLower('--Foo-Bar--');
console.log(toLower); // => '--foo-bar--'
const toUpper = _.toUpper('--foo-bar--');
console.log(toUpper); // => '--FOO-BAR--'
const trim = _.trim(' abc ');
console.log(trim); // => 'abc'
const trimEnd = _.trimEnd(' abc ');
console.log(trimEnd); // => ' abc'
const trimStart = _.trimStart(' abc ');
console.log(trimStart); // => 'abc '
const truncate = _.truncate('hi-diddly-ho there, neighborino');
console.log(truncate); // => 'hi-diddly-ho there, neighbo...'
const unescape = _.unescape('fred, barney, & pebbles');
console.log(unescape); // => 'fred, barney, & pebbles'
const upperCase = _.upperCase('--foo-bar--');
console.log(upperCase); // => 'FOO BAR'
const upperFirst = _.upperFirst('fred');
console.log(upperFirst); // => 'Fred'
const words = _.words('fred, barney, & pebbles');
console.log(words); // => ['fred', 'barney', 'pebbles']
// Util
const attempt = _.attempt(function() { return _.divide(1, 0); });
console.log(attempt); // => [Error: Divide by zero.]
const bindAll = _.bindAll(object, ['increment', 'square']);
console.log(bindAll); // => { 'increment': [Function: increment], 'square': [Function: square] }
const cond = _.cond([
[_.matches({ 'a': 1 }), _.constant('matches A')],
[_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
[_.stubTrue, _.constant('no match')]
]);
console.log(cond({ 'a': 1, 'b': 2 })); // => 'matches A'
const constant = _.constant(1);
console.log(constant); // => 1
const defaultTo = _.defaultTo(1, 10);
console.log(defaultTo); // => 1
const flow = _.flow([function(n) { return n * 3; }, function(n) { return n + 1; }]);
console.log(flow(1)); // => 4
const flowRight = _.flowRight([function(n) { return n * 3; }, function(n) { return n + 1; }]);
console.log(flowRight(1)); // => 4
const identity = _.identity(1);
console.log(identity); // => 1
const iteratee = _.iteratee({ 'a': 1 });
console.log(iteratee); // => [Function: matches]
const matches = _.matches({ 'a': 1, 'b': 2 });
console.log(matches({ 'a': 1, 'b': 2, 'c': 3 })); // => true
const matchesProperty = _.matchesProperty('a', 1);
console.log(matchesProperty({ 'a': 1, 'b': 2 })); // => true
const method = _.method('a.b');
console.log(method({ 'a': { 'b': _.constant(2) } })); // => 2
const methodOf = _.methodOf({ 'a': { 'b': _.constant(2) } }, 'a.b');
console.log(methodOf()); // => 2
const mixin = _.mixin({ 'foo': _.constant('foo') });
console.log(mixin.foo()); // => 'foo'
const noConflict = _.noConflict();
console.log(noConflict); // => undefined
const noop = _.noop();
console.log(noop); // => undefined
const nthArg = _.nthArg(1);
console.log(nthArg('a', 'b', 'c', 'd')); // => 'b'
const over = _.over([Math.max, Math.min]);
console.log(over(1, 2, 3, 4)); // => [4, 1]
const overEvery = _.overEvery([Boolean, isFinite]);
console.log(overEvery('1')); // => true
const overSome = _.overSome([Boolean, isFinite]);
console.log(overSome('1')); // => true
const property = _.property('a');
console.log(property({ 'a': 1 })); // => 1
const propertyOf = _.propertyOf({ 'a': { 'b': 2 } });
console.log(propertyOf({ 'a': { 'b': 2 } })); // => 2
const range = _.range(4);
console.log(range); // => [0, 1, 2, 3]
const rangeRight = _.rangeRight(-4);
console.log(rangeRight); // => [0, -1, -2, -3]
const runInContext = _.runInContext();
console.log(runInContext); // => [Function: runInContext]
const stubArray = _.stubArray();
console.log(stubArray); // => []
const stubFalse = _.stubFalse();
console.log(stubFalse); // => false
const stubObject = _.stubObject();
console.log(stubObject); // => {}
const stubString = _.stubString();
console.log(stubString); // => ''
const stubTrue = _.stubTrue();
console.log(stubTrue); // => true
const times = _.times(3, String);
console.log(times); // => ['0', '1', '2']
const toPath = _.toPath('a.b.c');
console.log(toPath); // => ['a', 'b', 'c']
const uniqueId = _.uniqueId('contact_');
console.log(uniqueId); // => 'contact_104'
// Properties
const VERSION = _.VERSION;
console.log(VERSION); // => '4.17.4'
const templateSettings = _.templateSettings;
console.log(templateSettings); // => { 'escape': /<%-([\s\S]+?)%>/g, 'evaluate': /<%([\s\S]+?)%>/g, 'interpolate': /<%=([\s\S]+?)%>/g, 'variable': '', 'imports': { '_': { 'escape': [Function: escape] } } }
const templateSettingsEscape = _.templateSettings.escape;
console.log(templateSettingsEscape); // => /<%-([\s\S]+?)%>/g
const templateSettingsEvaluate = _.templateSettings.evaluate;
console.log(templateSettingsEvaluate); // => /<%([\s\S]+?)%>/g