var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
import { clampToRange } from '../utils/number-utils';
import { isArray, isUndefined } from '../utils/type-utils';
export function appendArray(currentValue, sampleType) {
return __spreadArray(__spreadArray([], __read((currentValue ? currentValue : [])), false), __read((isArray(sampleType) ? sampleType : [sampleType])), false);
}
export function updateThreshold(currentValue, percent) {
return (isUndefined(currentValue) ? 1 : currentValue) * percent;
}
export function simpleHash(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = (hash << 5) - hash + str.charCodeAt(i); // (hash * 31) + char code
hash |= 0; // Convert to 32bit integer
}
return Math.abs(hash);
}
/*
* receives percent as a number between 0 and 1
*/
export function sampleOnProperty(prop, percent) {
return simpleHash(prop) % 100 < clampToRange(percent * 100, 0, 100);
}
//# sourceMappingURL=sampling.js.map