zoukankan      html  css  js  c++  java
  • 给Array本地对象增加一个原型方法,它用于删除数组条目中重复的条目(可能有多个),返回值是一个包含被删除的重复条目的新数组以及删除了重复条目的原数组。

    Array.prototype.distinct = function() {
        var ret = [];
        for (var i = 0; i < this.length; i++)
        {
            for (var j = i+1; j < this.length;) {   
                if (this[i] === this[j]) {
                    ret.push(this.splice(j, 1));
                } else {
                    j++;
                }
            }
         }
         return ret+" "+this;
    }
    //for test
    console.info(['a','b','c','d','b','a','e'].distinct());
  • 相关阅读:
    bootstrap以及考试复习
    HTML复习
    驼峰命名法和模态对话框
    dom和bom
    dom习题复习和讲解
    DOM
    属性扩展
    sql防注入式攻击
    自动生成编号
    删除,修改,添加
  • 原文地址:https://www.cnblogs.com/zyuan3478/p/4594592.html
Copyright © 2011-2022 走看看