Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some error in solutions #1

Open
BranDanny opened this issue Nov 13, 2019 · 2 comments
Open

Some error in solutions #1

BranDanny opened this issue Nov 13, 2019 · 2 comments

Comments

@BranDanny
Copy link

// Challenge 7
const intersection = (arrays) => {
return arrays.reduce((acc, curr) => {
return curr.filter(el => acc.includes(el));
});
};

// console.log(intersection([5, 10, 15, 20], [15, 88, 1, 5, 7], [1, 10, 15, 5, 20]));
Uncaught TypeError: curr.filter is not a function

Should be:
const intersection = (...arrays) => {
return arrays.reduce((acc, curr) => {
return curr.filter(el => acc.includes(el));
});
};

and similar error downside :)

@JoSaGuDu
Copy link

Yep, same error spotted here. An alternative solution is to rewrite the test statement:

Instead of :

// console.log(intersection([5, 10, 15, 20], [15, 88, 1, 5, 7], [1, 10, 15, 5, 20]));

test with:

// console.log(intersection([[5, 10, 15, 20], [15, 88, 1, 5, 7], [1, 10, 15, 5, 20]]));

Final code would be:

// Challenge 7
function intersection(arrays) {
  return arrays.reduce((acc, curr) => {
    return curr.filter(el => acc.includes(el));
 });
}

// console.log(intersection([[5, 10, 15, 20], [15, 88, 1, 5, 7], [1, 10, 15, 5, 20]]));

Same for challenge 8

@daneelf
Copy link

daneelf commented Jun 15, 2021

Actually, challenge 7 should be:

function intersection(...arrays) {
  return arrays.reduce((acc, curr) => {
    return curr.filter(el => acc.includes(el));
 });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants