Skip to content

Instantly share code, notes, and snippets.

@jgcmarins
Created March 20, 2021 00:16
Show Gist options
  • Save jgcmarins/e9a49120dc7d0cbd5b3cdab211354d44 to your computer and use it in GitHub Desktop.
Save jgcmarins/e9a49120dc7d0cbd5b3cdab211354d44 to your computer and use it in GitHub Desktop.
Curebase Technical Interview - Coding Problem (https://www.curebase.com/)
const readlineSync = require('readline-sync');
function isValid1(answer) {
return answer === 'y'
}
function isValid2(answer) {
return Number(answer) >= 18 && Number(answer) <= 75
}
// w/h^2 -> check if this value is between an range: greater than 30 is a problem
function isValid3(a, b) {
const h = Number(a);
const w = Number(b);
const result = w/(h * h);
return result < 30;
}
(() => {
const questions = [
{ question: 'Have you ever been diagnosed with diabetes?', isValid: isValid1 },
{ question: 'How old are you?', isValid: isValid2 },
{ question: 'How tall are you?', isValid: isValid3 },
{ question: 'How much do you weight?', isValid: undefined }
];
const answers = [];
for (const question of questions) {
const answer = readlineSync.question(question.question);
answers.push(answer);
}
let hasPassed = true;
for (let i = 0 ; i < questions.length ; i++) {
if (typeof questions[i].isValid === 'function' && !questions[i].isValid(answers[i], answers[i+1])) {
hasPassed = false;
break;
}
}
console.log(`You ${hasPassed ? 'passed' : 'failed'}.`);
})()
{
"name": "cli",
"version": "1.0.0",
"dependencies": {
"readline-sync": "^1.4.10"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment