Last active
October 1, 2019 02:02
-
-
Save CharlesRajendran/71ff7ce895cf9fca21fb4b81883066ce to your computer and use it in GitHub Desktop.
Generating Questions with Recursion
This file contains 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
// generating questions of some complexity for kids math | |
// ["5 + 3 =", "3 + 2 =", "0 + 3 =", "2 + 0 =", "1 + 2 ="] | |
function generateRandomInteger(complexity) { | |
return Math.floor(Math.random() * complexity); | |
} | |
function matchingPairs(complexity) { | |
const x = generateRandomInteger(complexity); | |
const y = generateRandomInteger(complexity); | |
if ((x + y) < complexity) { | |
return [x, y]; | |
} else { | |
return matchingPairs(complexity); | |
} | |
} | |
function randomQuestionGenerator(n, complexity) { | |
let questions = []; | |
for(let i = 0; i < n; i++) { | |
const [x, y] = matchingPairs(complexity); | |
questions.push(`${x} + ${y} =`); | |
}; | |
return questions; | |
} | |
const ques = randomQuestionGenerator(5, 10); | |
console.log(ques); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mock Interview : https://www.youtube.com/watch?v=sahZwVK64gk