You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-5Lines changed: 25 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,7 @@ __Algorithms practiced using JS__
77
77
3. Finding the Most Recurring Character
78
78
4. Sentence Capitalization
79
79
5. Palindromes
80
-
80
+
6. Mean, Median, and Mode
81
81
## Explanation
82
82
<b>1. String reversing</b>
83
83
<p>The string reversal algorithm is perhaps the most common JavaScript code challenge on the internet. In this article, we explore various string reversal techniques as a good number of string manipulation algorithms are dependent on ones ability to reverse a string. </p> <br>
@@ -447,15 +447,35 @@ method tests whether all elements pass the test or not which is implemented by p
447
447
<hr>
448
448
<hr>
449
449
450
-
<b>6. Name </b>
450
+
<b>6. Mean, Median, and Mode </b>
451
451
452
-
__The challenge:__ <p> </p>
452
+
__The challenge:__ <p>Given an array of numbers, calculate the mean, median, and mode. </p>
453
453
454
454
455
-
__Algorithmic Thinking:__ <p> </p>
455
+
__Algorithmic Thinking:__ <p>In terms of difficulty, the algorithm to find the mean of a collection of numbers is the easiest. Statistically, the mean is defined as the sum of the collection divided by its size. Therefore, we can simply use the array’s reduce method to calculate its sum and then divide that by its length. This algorithm has runtime complexities of linear time and constant space because every number needs to be added while no internal memory is necessary.
456
456
457
+
The algorithm to find the median of a collection is of medium difficulty. First, we need to sort the array, but if its size is even, we will need extra logic to deal with two middle numbers. In these cases, we will need to return the average of those two numbers. This algorithm has a linearithmic time complexity due to sorting and a linear space complexity because internal memory is needed to hold the sorted array.
457
458
458
-
__code Implementation:__ <p> </p>
459
+
The algorithm to find the mode is the most challenging. Since the mode is defined as the number or numbers that appear the most often, we will need to maintain a frequency table. To complicate things further, if every value appears the same number of times, there is no mode. In code, this means we will need to create a hash map that tallies the frequency of each unique number, and then loop through it to collect the maximum number or numbers, or none. Because every number needs to be counted to create the hash table which is held in memory, this algorithm has a linear time and space complexity. </p>
0 commit comments