Skip to content

Commit 0c6ca1b

Browse files
committed
mostLikely
1 parent 455e425 commit 0c6ca1b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

7_kyu/mostLikely.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## [Most Likely](https://www.codewars.com/kata/56644a421b7c94c622000056)
2+
3+
##### Story
4+
5+
- Create a function which compares two probabilities, returning true if the first one is most likely otherwise false.
6+
7+
- 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.
8+
9+
#### Examples (input -> output):
10+
11+
```js
12+
Input: ('1:3','1:2') - returns false as 1 in 3 is less likely than 1 in 2.
13+
```
14+
15+
#### Solution:
16+
17+
```js
18+
function mostLikely(prob1, prob2) {
19+
// Split the probabilities into numerators and denominators
20+
var prob1Parts = prob1.split(":").map(Number);
21+
var prob2Parts = prob2.split(":").map(Number);
22+
23+
// Calculate the fractions
24+
var prob1Fraction = prob1Parts[0] / prob1Parts[1];
25+
var prob2Fraction = prob2Parts[0] / prob2Parts[1];
26+
27+
// Compare the fractions and return the result
28+
return prob1Fraction > prob2Fraction;
29+
}
30+
```

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ Solutions to CodeWars programming tasks. I try to update every day
394394
</tr>
395395
<tr>
396396
<td><a href=" " > </a></td>
397-
<td><a href="7 kyu" > </a></td>
397+
<td><a href="https://github.com/esadakman/javaScript-coding-challenges/blob/master/7_kyu/mostLikely.md" >mostLikely</a></td>
398398
<td><a href="https://github.com/esadakman/javaScript-coding-challenges/blob/master/6_kyu/greekLeet.md" >GrεεκL33t</a></td>
399399
<td><a href="5 kyu" > </a></td>
400400
<td><a href="others " ></a></td>

0 commit comments

Comments
 (0)