Skip to content

Commit b8bf44b

Browse files
Add "Find missing numbers" kata
1 parent d39c3d4 commit b8bf44b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

7-kyu/find-missing-numbers.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<h1>Find missing numbers <sup><sup>7 Kyu</sup></sup></h1>
2+
3+
<sup>
4+
<a href="https://www.codewars.com/kata/56d02e6cc6c8b49c510005bb">
5+
<strong>LINK TO THE KATA</strong>
6+
</a> - <code>ARRAYS</code> <code>FUNDAMENTALS</code>
7+
</sup>
8+
9+
## Description
10+
11+
You will get an array of numbers.
12+
13+
Every preceding number is smaller than the one following it.
14+
15+
Some numbers will be missing, for instance:
16+
17+
```
18+
[-3,-2,1,5] //missing numbers are: -1,0,2,3,4
19+
```
20+
21+
Your task is to return an array of those missing numbers:
22+
23+
```
24+
[-1,0,2,3,4]
25+
```
26+
27+
## Solution
28+
29+
```javascript
30+
const findMissingNumbers = nums => {
31+
const minNumber = Math.min(...nums)
32+
const maxNumber = Math.max(...nums)
33+
34+
const missingNumbers = []
35+
36+
for (let i = minNumber + 1; i < maxNumber; i++) {
37+
if (nums.indexOf(i) === -1) missingNumbers.push(i)
38+
}
39+
40+
return missingNumbers
41+
}
42+
```

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ JavaScript katas on Codewars are programming challenges that help you improve yo
151151
- **[Exes and Ohs](./7-kyu/exes-and-ohs.md)**<br><sup>`FUNDAMENTALS`</sup>
152152
- **[Factorial](./7-kyu/factorial.md)**<br><sup>`FUNDAMENTALS`</sup>
153153
- **[Find Count of Most Frequent Item in an Array](./7-kyu/find-count-of-most-frequent-Item-in-an-array.md)**<br><sup>`DATA STRUCTURES` `FUNDAMENTALS`</sup>
154+
- **[Find missing numbers](./7-kyu/find-missing-numbers.md)**<br><sup>`ARRAYS` `FUNDAMENTALS`</sup>
154155
- **[Find The Duplicated Number in a Consecutive Unsorted List](./7-kyu/find-the-duplicated-number-in-a-consecutive-unsorted-list.md)**<br><sup>`ARRAYS` `ALGORITHMS`</sup>
155156
- **[Find the next perfect square!](./7-kyu/find-the-next-perfect-square.md)**<br><sup>`ALGEBRA` `FUNDAMENTALS`</sup>
156157
- **[Find the stray number](./7-kyu/find-the-stray-number.md)**<br><sup>`FUNDAMENTALS` `ALGORITHMS`</sup>

0 commit comments

Comments
 (0)