UNPKG

react-abtest

Version:

A simple React and React Native AB test component.

56 lines (45 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.randomInteger = randomInteger; exports.randomFloat = randomFloat; exports.customRange = customRange; exports.totalWeight = totalWeight; exports.getWeighedIndex = getWeighedIndex; exports.createHash = createHash; function randomInteger(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } function randomFloat(min, max) { return Math.random() * (max - min) + min; } function customRange(num, min, max) { return num * (max - min) + min; } function totalWeight(weights) { return weights.reduce(function (prev, cur) { return prev + cur; }); } function getWeighedIndex(weights, stopValue) { var sum = 0; var index = null; weights.some(function (weight, i) { sum += weight; if (stopValue <= sum) { index = i; return true; } return false; }); return index; } function createHash(str) { var i = 0; var hash = 0; for (i; i < str.length; i++) { hash = str.charCodeAt(i) + (hash << 6) + (hash << 16) - hash; } return hash >>> 0; }