squiggle/src/utility/GuesstimatorLibrary.js
2020-03-20 12:08:26 +00:00

26 lines
514 B
JavaScript

const _ = require("lodash");
const { Guesstimator } = require('@foretold/guesstimator/src');
const stringToSamples = (
text,
sampleCount,
inputs = [],
) => {
const [_error, { parsedInput, parsedError }] = Guesstimator.parse({ text:"=" + text });
const guesstimator = new Guesstimator({ parsedInput });
const {values, errors} = guesstimator.sample(
sampleCount,
inputs,
);
if (errors.length > 0){
return []
} else {
return values
}
};
module.exports = {
stringToSamples,
};