File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change
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
+ ```
Original file line number Diff line number Diff line change @@ -394,7 +394,7 @@ Solutions to CodeWars programming tasks. I try to update every day
394
394
</tr >
395
395
<tr >
396
396
<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>
398
398
<td><a href="https://github.com/esadakman/javaScript-coding-challenges/blob/master/6_kyu/greekLeet.md" >GrεεκL33t</a></td>
399
399
<td><a href="5 kyu" > </a></td>
400
400
<td><a href="others " ></a></td>
You can’t perform that action at this time.
0 commit comments