Tell us what’s happening:
my code works but instead of having [1, 1]
as output it has
[ [ 1 ], [ 1 ] ]
Your code so far
function destroyer(arr) {
const sample = Object.values(arguments);
// console.log(sample)
const array = sample.filter(x => Array.isArray(x) === true );
// console.log(array[0])
const toBeRemoved = sample.filter(x => Array.isArray(x) === false);
// console.log(toBeRemoved)
const targets = [];
const safe = [];
for( let i = 0; i < array[0].length; i++){
if(toBeRemoved.indexOf(array[0][i]) !== -1){
targets.push(i);
}
}
for(let a = 0; a < array[0].length; a++){
if(targets.indexOf(a) === -1 ){
if(a == 0){
let safetyMarkStart = array[0].slice(0,1);
safe.push(safetyMarkStart);
}
else{
let anyOtherSafetyMark = array[0].slice(a, a+1);
safe.push(anyOtherSafetyMark);
}
}
}
console.log(targets)
return safe;
}
console.log(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/116.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Seek and Destroy
Link to the challenge: