Why using arguments[i] in the code below gives error?

Why using arguments[i] in the code below gives error?
0

#1

not error

error


#2

Just to try - substitute args for arguments


#3

@rickstewart args will be the first argument ie [1,2,3]. I used a counter ‘i’ here to make my program general enough to handle more than 2 args. The program needs some correction to make it general enough to find symettric differnce of more that 2 arguments but first I have to solve this problem.


#4

You’re right - sorry about that - I didn’t look close enough or long enough…


#5

@rickstewart no need to say sorry.


#6

This is the way I usually make logic, am I doing wrong or is it fine?


@daemus this is the solution that I opted.


#7

why do I get “dont make functions within loop” warnings when I havent made any functions within loop?


#8

You’re getting that error on the second invocation of the filter callback. At that point, i+1 would be 2, resolving to arguments[2].indexOf(a). That element doesn’t exist, meaning that indexOf doesn’t exist.


#9

@daemus loop will run for i = 0 only then how come i will be 2 ?
In the for loop, condition is i < arguments.length - 1 // i < 1


#10

I stand corrected. I did not notice that in the conditional.


#11

You’ll want to save the original function’s arguments object into another variable, then access that within the filter callback.