mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-07 17:04:58 +01:00
44 lines
878 B
JavaScript
44 lines
878 B
JavaScript
|
|
export function findDiff(arr1, arr2) {
|
|
|
|
let both = [];
|
|
let firstOnly = [];
|
|
let secondOnly = [];
|
|
|
|
for (let e1 of arr1) {
|
|
for (let e2 of arr2) {
|
|
if (e1 === e2) {
|
|
both.push(e1);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (let e1 of arr1) {
|
|
if (both.indexOf(e1) === -1) {
|
|
firstOnly.push(e1);
|
|
}
|
|
}
|
|
|
|
for (let e2 of arr2) {
|
|
if (both.indexOf(e2) === -1) {
|
|
secondOnly.push(e2);
|
|
}
|
|
}
|
|
|
|
return [both, firstOnly, secondOnly]
|
|
}
|
|
|
|
export function flatten(arr, result = [], depth, _currLevel) {
|
|
_currLevel = _currLevel || 1;
|
|
for (let i = 0, length = arr.length; i < length; i++) {
|
|
const value = arr[i];
|
|
if (Array.isArray(value) && depth && _currLevel !== depth) {
|
|
flatten(value, result, depth, _currLevel ++);
|
|
} else {
|
|
result.push(value);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export const EMPTY_ARRAY = Object.freeze([]);
|