flash-section-list
Version:
SectionList base on FlashList
77 lines (75 loc) • 1.73 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.omit = exports.lcm = exports.findFirstProp = exports.binarySearchClosestIndex = void 0;
const omit = (obj, props, mutable = false) => {
if (obj === null || typeof obj !== 'object') {
return obj;
}
const copy = mutable ? obj : {
...obj
};
for (let i = 0; i < props.length; i++) {
const prop = props[i];
if (prop) {
delete copy[prop];
}
}
return copy;
};
exports.omit = omit;
const _gcd = (a, b) => {
while (b !== 0) {
let temp = b;
b = a % b;
a = temp;
}
return a;
};
const _lcm = (a, b) => {
return a * b / _gcd(a, b);
};
const lcm = numbers => {
return numbers.reduce((acc, cur) => _lcm(acc, cur), 1);
};
exports.lcm = lcm;
const findFirstProp = (obj, props) => {
if (!obj || typeof obj !== 'object') return;
for (let i = 0; i < props.length; i++) {
const prop = props[i];
const value = obj[prop];
if (value !== undefined) return value;
}
};
exports.findFirstProp = findFirstProp;
const binarySearchClosestIndex = (arr, value) => {
if (!arr?.length) return -1;
let low = 0;
let high = arr.length - 1;
while (low <= high) {
const mid = Math.floor((low + high) / 2);
const midValue = arr[mid];
if (midValue === value) {
return mid;
}
if (low === mid || high === mid) {
// return low or high
if (arr[high] <= value) {
return high;
}
return low;
}
// left
if (midValue > value) {
high = mid;
}
// right
else if (midValue < value) {
low = mid;
}
}
return -1;
};
exports.binarySearchClosestIndex = binarySearchClosestIndex;
//# sourceMappingURL=utils.js.map
;