-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMostLikely.js
More file actions
28 lines (24 loc) · 851 Bytes
/
Copy pathMostLikely.js
File metadata and controls
28 lines (24 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* Create a function which compares two probabilities, returning
* true if the first one is most likely otherwise false.
*
* For this exercise probability is
* expressed as two numbers separated by a
* colon e.g. a probability of 1 in 3 will be 1:3.
*
* So:
* Input: ('1:3','1:2') - returns false as 1 in 3 is less likely than 1 in 2.
*
* Kata URL: https://www.codewars.com/kata/56644a421b7c94c622000056
*
* @param {*} prob1
* @param {*} prob2
*/
function mostLikely(prob1, prob2) {
const [numerator1, denominator1] = prob1.split(":").map(Number);
const [numerator2, denominator2] = prob2.split(":").map(Number);
const actualProbability1 = numerator1 / denominator1;
const actualProbability2 = numerator2 / denominator2;
return actualProbability1 > actualProbability2;
}
console.log(mostLikely("1:3", "1:2")); // false