Skip to content

Commit 9d00d7c

Browse files
committed
removeDuplicates stretch problem added
1 parent c9bc064 commit 9d00d7c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

assignments/callbacks.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,19 @@ contains('gum', items, display);
4646

4747
const stretchArray = [1,5,23,5,7,2,0];
4848

49-
function removeDuplicates(array, cb) {
49+
const removeDuplicates = (array, cb) => {
5050
// removeDuplicates removes all duplicate values from the given array.
5151
// Pass the duplicate free array to the callback function.
5252
// Do not mutate the original array.
53-
//const filteredArr = array.filter(function(val, index, arr) { return index == self.indexOf(val);});
54-
const filteredArr = array.filter(function(elem, index, arr) { return index == self.indexOf(elem);});
55-
return cb('Filtered array:', filteredArr);
53+
const newArr = [];
54+
55+
for( let i = 0; i < array.length; i++ )
56+
{
57+
if( newArr.includes(array[i]) === false ){
58+
newArr.push(array[i]);
59+
}
60+
}
61+
return cb("Filtered Array: " + newArr);
5662
}
57-
removeDuplicates(stretchArray, display);
63+
64+
removeDuplicates(stretchArray, display);

0 commit comments

Comments
 (0)