Files
documentation/node_modules/@docusaurus/theme-common/lib/utils/jsUtils.js
2024-03-22 03:47:51 +05:30

29 lines
1.1 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// A replacement of lodash in client code
/**
* Gets the duplicate values in an array.
* @param arr The array.
* @param comparator Compares two values and returns `true` if they are equal
* (duplicated).
* @returns Value of the elements `v` that have a preceding element `u` where
* `comparator(u, v) === true`. Values within the returned array are not
* guaranteed to be unique.
*/
export function duplicates(arr, comparator = (a, b) => a === b) {
return arr.filter((v, vIndex) => arr.findIndex((u) => comparator(u, v)) !== vIndex);
}
/**
* Remove duplicate array items (similar to `_.uniq`)
* @param arr The array.
* @returns An array with duplicate elements removed by reference comparison.
*/
export function uniq(arr) {
// Note: had problems with [...new Set()]: https://github.com/facebook/docusaurus/issues/4972#issuecomment-863895061
return Array.from(new Set(arr));
}
//# sourceMappingURL=jsUtils.js.map