Skip to content

Instantly share code, notes, and snippets.

  • Save anonymous/56b153f9ea0696822e93 to your computer and use it in GitHub Desktop.
Save anonymous/56b153f9ea0696822e93 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/kobibr 's solution for Bonfire: Seek and Destroy
// Bonfire: Seek and Destroy
// Author: @kobibr
// Challenge: http://www.freecodecamp.com/challenges/bonfire-seek-and-destroy?solution=%2F*%20jshint%20esnext%3A%20true%20*%2F%0Afunction%20destroyer(arr)%20%7B%0A%20%20%27use%20strict%27%3B%0A%20%20var%20args%20%3D%20Array.prototype.slice.call(arguments)%3B%0A%20%20args.splice(0%2C1)%3B%0A%20%20for(let%20inR%20in%20arr)%20%7B%0A%20%20%20%20for(let%20inG%20in%20args)%20%7B%0A%20%20%20%20%20%20if(arr%5BinR%5D%20%3D%3D%20args%5BinG%5D)%7B%0A%20%20%20%20%20%20%20%20delete%20arr%5BinR%5D%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20%0A%20%20function%20filterred%20(obj)%7B%0A%20%20%20%20return%20Boolean(obj)%3B%0A%20%20%7D%0A%20%20%0A%20%20var%20waitingRoom%20%3D%20arr.filter(filterred)%3B%0A%20%20return%20waitingRoom%3B%0A%7D%0A%0Adestroyer(%5B1%2C%202%2C%203%2C%201%2C%202%2C%203%5D%2C%202%2C%203)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
/* jshint esnext: true */
function destroyer(arr) {
'use strict';
var args = Array.prototype.slice.call(arguments);
args.splice(0,1);
for(let inR in arr) {
for(let inG in args) {
if(arr[inR] == args[inG]){
delete arr[inR];
}
}
}
function filterred (obj){
return Boolean(obj);
}
var waitingRoom = arr.filter(filterred);
return waitingRoom;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment