Skip to content

Create custom exponent method #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion bot/controllers/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ const nodemailer = require('nodemailer');
// Modified to fit style guide from this SO answer:
// https://stackoverflow.com/a/39774334
const generateCode = (n) => {
// Workaround method for Math.pow() and ** operator
const pow = (base, exp) => {
let result = 1;
for (let i = 0; i < exp; i += 1) {
result *= base;
}
return result;
};
const add = 1;
let max = 12 - add;
let min = 0;
if (n > max) {
return generateCode(max) + generateCode(n - max);
}
max = 10000000;
max = pow(10, n + add);
min = max / 10;
const number = Math.floor(Math.random() * (max - (min + 1))) + min;
return ('' + number).substring(add);
Expand Down