1
1
/**
2
2
3
3
** 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.
4
6
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']
7
9
8
- The function should remove duplicate elements.So the result should be:
10
+ */
9
11
10
-
12
+ /**
13
+ * Checks your solution against correct solution
14
+ * @param {Array } array your solution
15
+ * @returns boolean
11
16
*/
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 ;
12
21
22
+ for ( let i = 0 ; i < solution . length ; i ++ ) {
23
+ if ( array [ i ] !== solution [ i ] ) return false ;
24
+ }
25
+ return true ;
26
+ }
13
27
14
28
// WRITE YOUR FUNCTION HERE
15
29
16
30
const letters = [ 'a' , 'b' , 'c' , 'd' , 'a' , 'e' , 'f' , 'c' , 'b' ] ;
17
-
18
31
removeDuplicates ( letters ) ;
19
32
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