The first array is filtered in a search for arr elements that not found in targets. It seems that filter is not working. What is incorrect?
function destroyer(array, ...iv) {
let targets = [...iv];
let arr = [...array];
arr.filter(element => {
return !arr.indexOf(element);
});
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36 Edg/88.0.705.56
.
Challenge: Seek and Destroy
Link to the challenge:
The return part of the callback can search targets.
return !targets.indexOf(element);
Thank you. Let me rework something.
function destroyer(array, ...iv) {
let targets = [...iv];
let arr = [...array];
let result = arr.filter(element => {
return targets.indexOf(element) === -1;
});
return result;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Pikachu accepts me! I have at last made my own solution for this challenge.
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).
system
Closed
August 23, 2021, 10:50am
8
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.