|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | import { dropRightWhile as dropRightWhile$1 } from '../../array/dropRightWhile.mjs';
|
|---|
| 2 | import { identity } from '../../function/identity.mjs';
|
|---|
| 3 | import { property } from '../object/property.mjs';
|
|---|
| 4 | import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|---|
| 5 | import { matches } from '../predicate/matches.mjs';
|
|---|
| 6 | import { matchesProperty } from '../predicate/matchesProperty.mjs';
|
|---|
| 7 |
|
|---|
| 8 | function dropRightWhile(arr, predicate = identity) {
|
|---|
| 9 | if (!isArrayLike(arr)) {
|
|---|
| 10 | return [];
|
|---|
| 11 | }
|
|---|
| 12 | return dropRightWhileImpl(Array.from(arr), predicate);
|
|---|
| 13 | }
|
|---|
| 14 | function dropRightWhileImpl(arr, predicate) {
|
|---|
| 15 | switch (typeof predicate) {
|
|---|
| 16 | case 'function': {
|
|---|
| 17 | return dropRightWhile$1(arr, (item, index, arr) => Boolean(predicate(item, index, arr)));
|
|---|
| 18 | }
|
|---|
| 19 | case 'object': {
|
|---|
| 20 | if (Array.isArray(predicate) && predicate.length === 2) {
|
|---|
| 21 | const key = predicate[0];
|
|---|
| 22 | const value = predicate[1];
|
|---|
| 23 | return dropRightWhile$1(arr, matchesProperty(key, value));
|
|---|
| 24 | }
|
|---|
| 25 | else {
|
|---|
| 26 | return dropRightWhile$1(arr, matches(predicate));
|
|---|
| 27 | }
|
|---|
| 28 | }
|
|---|
| 29 | case 'symbol':
|
|---|
| 30 | case 'number':
|
|---|
| 31 | case 'string': {
|
|---|
| 32 | return dropRightWhile$1(arr, property(predicate));
|
|---|
| 33 | }
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | export { dropRightWhile };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.