8000 Updated JS2 Week3 example2 to correctly check for correct solution by cgduncan7 · Pull Request #542 · HackYourFuture/JavaScript2 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions Week3/js-exercises/ex2-RemoveDuplicates.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
/**

** Exercise 2: The lottery machine **
Write a function called removeDuplicates. This function accept an array as an argument
does not return anything but removes any duplicate elements from the array.

Write a function called removeDuplicates. This function accept an array as an argument
does not return anything but removes any duplicate elements from the array.
The function should remove duplicate elements. So the result should be:
['a', 'b', 'c', 'd', 'e', 'f']

The function should remove duplicate elements.So the result should be:
*/


/**
* Checks your solution against correct solution
* @param {Array} array your solution
* @returns boolean
*/
function checkSolution(array) {
const solution = ['a', 'b', 'c', 'd', 'e', 'f'];
if (array == null) return false;
if (array.length !== solution.length) return false;

for (let i = 0; i < solution.length; i++) {
if (array[i] !== solution[i]) return false;
}
return true;
}

// WRITE YOUR FUNCTION HERE

const letters = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c', 'b'];

removeDuplicates(letters);

if (letters === ['a', 'b', 'c', 'd', 'e', 'f'])
console.log("Hooray!")
if (checkSolution(letters)) {
console.log("Hooray!");
}
0