@gorpacrate/core-graphics
Version:
A core library for creating shape-based graphic editors
53 lines • 1.85 kB
JavaScript
;
exports.__esModule = true;
exports.noop = function () { return undefined; };
function getPairs(arr) {
var res = [];
arr.forEach(function (point) {
if (res.length === 0) {
res = [[point]];
return;
}
var last = res[res.length - 1];
if (last.length === 0) {
res[res.length - 1] = [point];
return;
}
if (last.length === 1) {
res[res.length - 1] = last.concat([point]);
return;
}
if (last.length === 2) {
res = res.concat([[point]]);
return;
}
});
return res;
}
exports.getPairs = getPairs;
var symFilterFunction = function (arr1, arr2) { return (arr1.filter(function (item) { return (arr2.indexOf(item) === -1); })); };
function symmetricDifference2(arr1, arr2) {
// Returns items in arr1 that don't exist in arr2
// Run filter function on each array against the other then get unique values
return (symFilterFunction(arr1, arr2).concat(symFilterFunction(arr2, arr1)).filter(function (item, idx, arr) { return (
// Keep any items that are unique - the index of the current item === index of the first occurrence in the array
arr.indexOf(item) === idx); }));
}
exports.symmetricDifference2 = symmetricDifference2;
function symmetricDifference() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return args.reduce(symmetricDifference2, []);
}
exports.symmetricDifference = symmetricDifference;
function hasInArr(what, where) {
return where.indexOf(what) > -1;
}
exports.hasInArr = hasInArr;
function uniq(arr) {
return arr.filter(function (value, index, self) { return (self.indexOf(value) === index); });
}
exports.uniq = uniq;
//# sourceMappingURL=data.js.map