In this challenge you will be determining how controversial a vote is, given an array of other votes, by figuring out a number called the C-factor. What is the C-factor, you ask?
Well, imagine you've got multiple votes on an election. We'll use
0 for the sake of the challenge to represent two different candidates in an election. Here's the ten votes in our sample election:
Now, say we want to find the C-factor of any vote for candidate
0. We can do that with the following function:
$$ f(o,v) = abs(o-mean(v)) $$
o is the vote we want to determine the C-factor for, and
v is an array of votes. So, using our function, to get the C-factor of any vote for candidate
$$ f(0, [0,1,1,0,1,1,1,0,1,1]) = 0.7 $$
A lower C-factor shows that the vote was less controversial in comparison to the other votes. So, a vote for candidate
0 is more different from the other votes than a vote for candidate
1. In comparison, the C-factor for a candidate
1 vote is \$0.3\$, so it is less controversial because it is more like the other votes.
Write a function \$f(o,v)\$ to determine the C-factor of a vote
o given results of a vote
omust be an integer, either
vmust be an array (or similar container type depending on language specifications) of arbitrary length containing zeroes and ones.
The function should return or print to the console the resulting C-factor given the function parameters, using the formula above or a modified method.
Good luck! The least bytes wins (winner chosen in five days).