什么将是一个很好的算法,以消除类似下面的阵列上易受骗的人......
What would be a nice algorithm to remove dupes on an array like below...
var allwords = [
['3-hidroxitiramina', '3-hidroxitiramina'],
['3-hidroxitiramina', '3-hidroxitiramina'],
['3-in-1 block', 'bloqueo 3 en 1'],
['abacterial', 'abacteriano'],
['abacteriano', 'abacteriano'],
['abciximab', 'abciximab'],
...
只是为了澄清,我想的一个
Just to clarify, I would want one of the
['3-hidroxitiramina', '3-hidroxitiramina'],
要被删除,因此只有一个
To be removed, so there is just one
:误读,读你的澄清后,我会建议:
[edit]: misread, after reading your clarification I'd suggest:
var i = allwords.length-1, prev='';
do {
if (allwords[i].join('/') === prev) {
allwords.splice(i,1);
}
prev = allwords[i].join('/');
} while (i-- && i>-1);
(扭转循环是一个优化步骤)
(reversing the loop is a optimization step)