@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
33 lines (32 loc) • 916 B
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.filterAndSeparate = filterAndSeparate;
exports.findDuplicates = findDuplicates;
/****
*
* separates an single array into an array of successes and an array of fails
* success is based on the truthiness of an predicate function
*
* successes are the first value of the return tuple
*****/
function filterAndSeparate(items, predicate) {
const truthy = [];
const falsey = [];
for (const item of items) {
if (predicate(item)) {
truthy.push(item);
}
else {
falsey.push(item);
}
}
return [truthy, falsey];
}
/*
from an array of items, returns of all duplicates found
*/
function findDuplicates(items) {
return items.filter((item, index) => items.indexOf(item) !== index);
}