Created
July 31, 2020 05:39
-
-
Save ilonacodes/06bad11e57ddfbb48f87102c5136c7ac to your computer and use it in GitHub Desktop.
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
// ©2020 Ilona Codes. All rights reserved. | |
// Playing with weight values changes results | |
const weights = { | |
'A': -2, | |
'B': -1, | |
'C': 1, | |
'D': 2, | |
}; | |
const determineInvestorType = questions => { | |
// we initialize answer option counts | |
const counts = { | |
'A': 0, | |
'B': 0, | |
'C': 0, | |
'D': 0, | |
}; | |
// we count how many answers are of each option | |
questions.forEach(question => { | |
counts[question.chosen]++; | |
}); | |
// we calculate the weighted score | |
let score = 0; | |
Object.keys(counts).forEach(letter => { | |
score += weights[letter] * counts[letter]; | |
}); | |
// we determine in which range does the score lie | |
let investorType; | |
if (score < -5) { | |
investorType = 'conservative'; | |
} else if (score < 5) { | |
investorType = 'balanced'; | |
} else if (score < 10) { | |
investorType = 'growth'; | |
} else { | |
investorType = 'aggressive_growth'; | |
} | |
return { | |
investorType: investorType, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment