I opened the Firebug console, took 30 seconds to write 30 seconds, and the results were as follows: (x is the target array, y is the result of removing duplicate elements)
Copy Code code as follows:
var x=[1,1,3,4,5,3];
var y=[];
var tarray=function (I,arr) {
var Yap=false;
for (Var j=0;j<arr.length;j++) {
if (arr[j]==i) {yap=true;break;};
}
if (!yap) Arr.push (i);
};
for (Var t=0;t<x.length;t++) {
Tarray (X[t],y);
}
alert (y.length);
Alert (y.tostring ());
The answer is not unique, and there are no standard answers, so the above code is right and wrong. What if the array is a complex array of objects? What if the array contains more than one empty object {}? To know that JS has a lot of special or even bug in the phenomenon, alert ({}=={}) to see what's going on ...
Note: If anyone has a standard answer welcome comments inside Send let everyone learn to learn.
The question-makers themselves will not take these questions into account.
Do not learn to do the problem, in the actual work encountered problems when the ability to solve problems effectively is truly valuable.
Places to be noted for additional:
There's a problem to be aware of.
Arr[j]==i you seem to refer to the equality judgment when an array element is a number type ...
But often we may have to make equality judgments about different types of ... This is the practical application of the problem should be considered
Case of 1!=new number (1)
The situation of null==undefined
0== "0" situation and so on
So obviously simple = = and = = are not suitable.
A Equals method should be implemented independently to make equality judgments ... To set rules based on requirements
My example is an array of number types, which is designed to express an attitude about what to do in an interview. Practical application should be considered according to the actual needs. Unless the actual work required or I am a JS academic researcher, otherwise I will not be independent to implement a equals method. Foreign developers tend to follow a credo: "Do the simplest Thing that could possibly Work", meaning "don't overdo, apply first", my work experience of these years also often confirms this truth. I don't know what you think.