Seek and Destroy JavaScript Free Code Camp

preview_player
Показать описание

Fan funding goes towards buying the equipment necessary to deliver 4k videos, 4k webcam, and a high quality microphone better audio. Any support is very appreciated!

My channel is here for aspiring programmers to learn easier and help debug any issues from the many great free resources available on the web.

Check out my other videos going over HTML, CSS, Ruby, Ruby on Rails, Java, JavaScript, Python, PHP, SQL, Command Line, BootStrap, jQuery, and WordPress from CodeCademy, CodeCombat, FreeCodecamp and more!

-~-~~-~~~-~~-~-
Please watch: "How I Became a Developer | My Developer Journey of the Last 3 Years | Ask a Dev"
-~-~~-~~~-~~-~-
Рекомендации по теме
Комментарии
Автор

Hey, thanks for the help, I was stuck for a bit on this one for whatever reason, haha! I'm sure you already know by now, but for the last bit you could just type out: return placeholder.filter(Boolean); to achieve the same effect without going through an entire function! Edit: nvm, plenty of people have mentioned it already, haha! Keep up the good work!

jacobhightower
Автор

Thank you buddy for your great explanation..I used from() to convert arguments into array. I was confused how to use filter(), you provided an awesome solution..

subhsamal
Автор

thx man, you're literally my tutor ;)

TheWhatever
Автор

I think this is the simplest solution:

function destroyer(arr) {


var args =

function check(i) {

return args.indexOf(i, 1)==-1;

}

var filtered = arr.filter(check);
return filtered;
}

theodorep.
Автор

Does anyone know as to why in the beginning it only returns the array instead of the entire string? If you're returning 'destroyer' shouldn't it return Everything in the ()?

nezerworld
Автор

Confused as to why the null values are created ...

PastryFanatic
Автор

thanks for posting. yes, I found this difficult as well. Was very close to the same solution.
A few hangups I have.
- deleting an element from an array while looping through that array.
- the filter method - this still bothers me, I'm looking for more tutorials/exercises using filter. Also - equivalent methods in python and Java.

MatthewTaylorAu
Автор

thanks. your solutions make great sense for a beginner like me. Btw it still works without args.splice(0, 1) at line 4. why would arr.length and args.length have different values. trying to get that

anon
Автор

when does arr go from being [1, 2, 3, 1, 2, 3] to [1, null, null, 1, null, null]?
I tried commenting out portions of the answer and it seems like the for loops are causing this change but I don't know why that is.

edit: nevermind, figured it out. delete gets rid of the content of the element but keeps the element position; therefore, null is in its place.

wantsoobaroo
Автор

when you used .filter() you could easily write this: return arr.filter(Boolean);
So with that you could easily delete all 'null', because with Boolean you delete every variable of boolean type

daviddume
Автор

Could've just used placeHolder = arr.filter(Boolean); as the filter code. No need to write another function after that. Good job though!

justinallen
Автор

Please have a look at this
function destroyer(arr) {
// Remove all the values
var args =
var filtering = args.splice(0, 1);
return arr.filter(function (element) {
return args.indexOf(element) === -1;
});
}

kouIShereNOfear
Автор

that's way too much code and its confusing. I tried this and it worked

if(destroyer([1, 2, 3, 1, 2, 3], 2, 3)

function destroyer(arr) {

var mustRemove = [];
for(var i = 1; i < arguments.length; i++){
// arguments object to take additional arguments into account (2, 3)
}

var destroyer = []; //array that will eventually contain differing values

for(i = 0; i < arr.length; i++){ //looping through arr because we're checking this array for values belonging to the MR Array
if(mustRemove.indexOf(arr[i]) === -1){ //conditional statement to push unequal values into the destroyer array
destroyer.push(arr[i]);
}
}

return destroyer;


}

mugrad
Автор

function destroyer(arr) {
const args = Array.from(arguments);
return arr.filter( val => args.indexOf(val) === -1);
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Fred
Автор

My 2 methods of solving it :

// Method 1
function destroyer(arr) {
var args = Array.from(arguments);
args.splice(0, 1);
return arr.filter(function(val){
return args.indexOf(val) == -1
});
}

// Method 2
function destroyer(arr) {
arr1 = Array.from(arguments);
for (a=1;a<arr1.length;a++){
arr = number != arr1[a]
});
}return arr
}

AndressAndress
Автор

<script>
function destroyer(arr) {
for (var i=1;i<arguments.length;i++){
for (var j=0;j<arr.length;j++){
if (arr[j]===arguments[i]) arr.splice(j, 1);
}
}
return arr;
}

var result = destroyer([1, 2, 3, 1, 2, 3, 4, 5], 2, 3);
alert(result);
</script>

//This code working fine, but I want to dynamically pass values on destroyer(), means Take input box, in that i wrote [1, 2, 3, 1, 2, 3, 4, 5], 2, 3 then click the button output shown in alert.

Rockygaming
Автор

Not using .filter:

function destroyer(arr) {
// Remove all the values
var args =
args.splice(0, 1);
var hola = [];
for(var i = 0; i < arr.length; i++){

hola.push(arr[i]);
}
}
return hola;
}

pablerdo
Автор

OK, shorter version below...





function destroyer(ar){var ar.filter(x=>!a.includes(x))}

VKBteamkiller
Автор

Filter in action again! - below :-)





function destroyer(){var

VKBteamkiller
Автор

function destroyer(arr) {
var args =
args.splice(0, 1);
for(var i =0 ; i<arr.length;i++){
for(var j=0;j<args.length;j++){
if(args[j]==arr[i]){
arr.splice(i, 1);
i--;
}
}
}
return arr;
}

underRated
welcome to shbcf.ru