Rest/unstructured parameters troubles with strict mode

My code is right and runs well in my machine. It passes on all FCC’s test cases.

However, it does not run on FCC platform. I think it has something to do with the use of strict mode on FCC.

My code:


function destroyer (lista, ...arguments){
//console.log(lista, arguments)
let not_destroyed = [];
let src_list = lista;
let check = arguments;
for (i in lista) {
    //console.log(lista[i]);
    if (arguments.includes(lista[i])==false) {
        //console.log(lista[i])
        not_destroyed.push(lista[i])
    }
}
return not_destroyed
}

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0.

Challenge: Seek and Destroy

Link to the challenge:

Is there a way os solving this without using something like:

var args = Array.prototype.slice.call(arguments); ?

How can I solve this?

Thanks in advance.

You didn’t declare i.

Thanks for the help.

I have just put for (var i in lista) . However, it is not enough to solve the problem.

FCC’s console returns this Syntax error:

SyntaxError: unknown: Binding ‘arguments’ in strict mode (1:30)

First, the names eval and arguments can’t be bound or assigned in language syntax. All these attempts to do so are syntax errors:

'use strict';
eval = 17;
arguments++;
++eval;
var obj = { set p(arguments) { } };
var eval;
try { } catch (arguments) { }
function x(eval) { }
function arguments() { }
var y = function eval() { };
var f = new Function('arguments', "'use strict'; return 17;");

Second, strict mode code doesn’t alias properties of arguments objects created within it. In normal code within a function whose first argument is arg , setting arg also sets arguments[0] , and vice versa (unless no arguments were provided or arguments[0] is deleted). arguments objects for strict mode functions store the original arguments when the function was invoked. arguments[i] does not track the value of the corresponding named argument, nor does a named argument track the value in the corresponding arguments[i] .

function f(a) {
  'use strict';
  a = 42;
  return [a, arguments[0]];
}
var pair = f(17);
console.assert(pair[0] === 42);
console.assert(pair[1] === 17);
1 Like

Thanks!

Changing arguments to argumentos solves the problem:


function destroyer (lista,...argumentos){

    let not_destroyed = [];
    let src_list = lista;
    var check = Array.prototype.slice.call(argumentos);

    for (var i in lista) {

        if (argumentos.includes(lista[i])==false) {

            not_destroyed.push(lista[i])
        }
    }
    
    return not_destroyed
}