Last active
October 8, 2017 21:24
-
-
Save PDXIII/3731cceda89fcf6e6d9b9fe89f93d4ce to your computer and use it in GitHub Desktop.
This script generates an array of integer calculations in a range between 0 and 100.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function uuidv4() { | |
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c=>(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)) | |
} | |
function add(num1, num2) { | |
return num1 + num2; | |
} | |
function substract(num1, num2) { | |
return num1 - num2; | |
} | |
function multiply(num1, num2) { | |
return num1 * num2; | |
} | |
function devide(num1, num2) { | |
return num1 / num2; | |
} | |
function main() { | |
var problems = []; | |
var range = 100; | |
for (var num1 = 0; num1 <= range; num1++ ) { | |
for (var num2 = 0; num2 <= range; num2++ ) { | |
if (num1 + num2 <= range) { | |
var problem = { | |
id: uuidv4(), | |
type: "ADDITION", | |
num1: num1, | |
num2: num2, | |
result: add(num1, num2), | |
str: `${num1} + ${num2} = ${add(num1, num2)}` | |
}; | |
problems.push(problem) | |
} | |
} | |
} | |
for (var num1 = 0; num1 <= range; num1++ ) { | |
for (var num2 = 0; num2 <= range; num2++ ) { | |
if (num1 >= num2) { | |
var problem = { | |
id: uuidv4(), | |
type: "SUBSTRACTION", | |
num1: num1, | |
num2: num2, | |
result: substract(num1, num2), | |
str: `${num1} − ${num2} = ${substract(num1, num2)}` | |
}; | |
problems.push(problem) | |
} | |
} | |
} | |
for (var num1 = 0; num1 <= range; num1++ ) { | |
for (var num2 = 0; num2 <= range; num2++ ) { | |
if (num1 * num2 <= range) { | |
var problem = { | |
id: uuidv4(), | |
type: "MULTIPLICATION", | |
num1: num1, | |
num2: num2, | |
result: multiply(num1, num2), | |
str: `${num1} × ${num2} = ${multiply(num1, num2)}` | |
}; | |
problems.push(problem) | |
} | |
} | |
} | |
for (var num1 = 0; num1 <= range; num1++ ) { | |
for (var num2 = 0; num2 <= range; num2++ ) { | |
if (num1 % num2 == 0) { | |
var problem = { | |
id: uuidv4(), | |
type: "DIVISION", | |
num1: num1, | |
num2: num2, | |
result: devide(num1, num2), | |
str: `${num1} ÷ ${num2} = ${devide(num1, num2)}` | |
}; | |
problems.push(problem) | |
} | |
} | |
} | |
console.log(JSON.stringify(problems)); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment