@natewilcox/wrong-answer
Version:
Returns a wrong answer to math questions
24 lines (23 loc) • 845 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addTwoInts = void 0;
const random_1 = __importDefault(require("random"));
function addTwoInts(a, b) {
const realAnswer = a + b;
let places = 0;
if (realAnswer == 0)
places = 1;
else if (realAnswer < 0)
places = +(realAnswer.toString().length - 3);
else if (realAnswer > 0)
places = +(realAnswer.toString().length - 2);
if (places <= 0)
places = 1;
let seed = random_1.default.int(1, Math.pow(10, places));
let sign = random_1.default.int(1, 2) == 1 ? 1 : -1;
return +realAnswer + (seed * sign);
}
exports.addTwoInts = addTwoInts;