Skip to content

Instantly share code, notes, and snippets.

@Hoodgail
Last active September 16, 2020 23:25
Show Gist options
  • Save Hoodgail/215bd1cc827d956871e85d3dc9f5b131 to your computer and use it in GitHub Desktop.
Save Hoodgail/215bd1cc827d956871e85d3dc9f5b131 to your computer and use it in GitHub Desktop.
/*
@author = Hoodgail Benjamin
@warning = the minimum percentage of a quizz with 10 questions would be 75% depending on your work or the story
*/
let sum = "When Alta was 17, her family took a vacation in Vermilion, Ohio. Alta asked some boys to play catch with her. Soon she was showing them her best fastball. The boys were so impressed that they told the town's mayor about the girl pitcher. The mayor came to watch her play. He, too, was floored.".split(" ")
let answers = ["No one treated her well.", "She was smaller than all the boys.", "She was a girl, and girls get tired faster.", "She had to play in a long skirt."]
let most_valid = []
const chunk = arr => arr.length > 2 ? [arr.slice(0, 2), ...chunk(arr.slice(2), 2)] : [arr];
answers.forEach(function(an, id){
chunk(sum).forEach(function(words){
let word = words.join(" ")
if(!most_valid[id]) most_valid[id] = 0;
if(an.includes(word)) {
most_valid[id] += 1
}
})
})
let correct_index = most_valid.indexOf(Math.max(...most_valid));
let correct_answer = answers[correct_index]
console.log(`The correct answer is ${"ABCDF"[correct_index]}`, correct_answer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment