Basic Algorith Scripting: Seek and Destroy
See original GitHub issueSeek and Destroy
https://www.freecodecamp.com/challenges/seek-and-destroy#?solution=%0Afunction%20destroyer(arr)%20%7B%0A%20%20%2F%2F%20Remove%20all%20the%20values%0A%20%20for%20(var%20i%20%3D%201%3B%20i%20%3C%3D%20arguments.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20%0A%20%20%20%20arr%20%3D%20arr.filter(function%20(value)%20%7B%0A%20%20%20%20%0A%20%20%20%20%20%20return%20value%20!%3D%3D%20this%3B%0A%20%20%20%20%7D%2C%20arguments%5Bi%5D)%3B%0A%20%20%7D%0A%20%20return%20arr%3B%0A%7D%0A%0Adestroyer(%5B3%2C%205%2C%201%2C%202%2C%202%5D%2C%202%2C%203%2C%205)%3B%0A
Issue Description
The code passes every test, but still, after hitting ctrl+enter nothing happens.
Browser Information
- Browser Name, Version: Google Chrome, 50.0.2661.102 m
- Operating System: Windows 10
- Mobile, Desktop, or Tablet: Desktop
Your Code
function destroyer(arr) {
// Remove all the values
for (var i = 1; i <= arguments.length; i++) {
arr = arr.filter(function (value) {
return value !== this;
}, arguments[i]);
}
return arr;
}
destroyer(["tree", "hamburger", 53], "tree", 53);
Screenshot
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
freeCodeCamp Challenge Guide: Seek and Destroy
Please explain for loop in Seek and Destroy. Basic Algorithm Scripting problem: Seek and Destroy, Get hint. Intermediate code solution.
Read more >CodeChallenge/Seek and Destroy.md at master - GitHub
Seek and Destroy. You will be provided with an initial array (the first argument in the destroyer function), followed by one or more...
Read more >Seek and Destroy — The JavaScript Algorithm - Medium
Summary: Introduction to the “Seek and Destroy” algorithm. Nested Loops; Array Iteration Methods; Rest Parameters Syntax. References:.
Read more >JavaScript Algorithm: Seek and Destroy - Level Up Coding
You are given an array containing either strings, integers or both. Following the array are one or more arguments. The goal of the...
Read more >Basic Algorithm Scripting #14: Seek and Destroy ... - CodePen
This is my solution for the 14th Basic Algorithm Scripting challenge at freeCodeCamp, which is called Seek and Destroy....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@erictleung Yes. That is correct.
@Frozenprobe since you are using
this
keyword, the scope (Lexical Scoping) changes while evaluating the tests, and the behavior is unpredictable depending on the browser.I am not sure if you are aware what that means. But as a best practice if you use below, you should be able to pass the challenge.
On that thought maybe we can add that in the seed code for the Algorithms? Not sure I don’t want to be confusing campers suddenly with this topic. But that’s the way JavaScript Closures work.
@MarcCoet Nope its not “bad” practice per say, but its a work around for the environment you are in, in most practical implementations, you may never need this kind of a work around, but most importantly you need to know what
'use strict';
does, and how it binds the variable to the context of the scope of the function.