Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93ac0fb

Browse files
authored
Merge pull request HackYourFuture#542 from cgduncan7/update-week3-ex2
Updated JS2 Week3 example2 to correctly check for correct solution
2 parents b6e4913 + f17e72b commit 93ac0fb

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
/**
22
33
** Exercise 2: The lottery machine **
4+
Write a function called removeDuplicates. This function accept an array as an argument
5+
does not return anything but removes any duplicate elements from the array.
46
5-
Write a function called removeDuplicates. This function accept an array as an argument
6-
does not return anything but removes any duplicate elements from the array.
7+
The function should remove duplicate elements. So the result should be:
8+
['a', 'b', 'c', 'd', 'e', 'f']
79
8-
The function should remove duplicate elements.So the result should be:
10+
*/
911

10-
12+
/**
13+
* Checks your solution against correct solution
14+
* @param {Array} array your solution
15+
* @returns boolean
1116
*/
17+
function checkSolution(array) {
18+
const solution = ['a', 'b', 'c', 'd', 'e', 'f'];
19+
if (array == null) return false;
20+
if (array.length !== solution.length) return false;
1221

22+
for (let i = 0; i < solution.length; i++) {
23+
if (array[i] !== solution[i]) return false;
24+
}
25+
return true;
26+
}
1327

1428
// WRITE YOUR FUNCTION HERE
1529

1630
const letters = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c', 'b'];
17-
1831
removeDuplicates(letters);
1932

20-
if (letters === ['a', 'b', 'c', 'd', 'e', 'f'])
21-
console.log("Hooray!")
33+
if (checkSolution(letters)) {
34+
console.log("Hooray!");
35+
}

0 commit comments

Comments
 (0)