<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                12. 實現數組去重你都有哪些辦法? ~~~ //=>數組去重(不改變原有數組) //1.對象鍵值對處理(推薦) // Array.prototype.myUnique = function () { // //=>this:ary 我們需要操作的數組,如果不想改變原有的數組,我們需要把要操作的數組克隆一份一模一樣的處理,處理的都是克隆的這個數組 // let _this = [...this], // let _this = this.slice(0) // obj = {}; // for (let i = 0; i < _this.length; i++) { // let item = _this[i]; // if (typeof obj[item] !== 'undefined') { // //=>當前迭代的這一項在數組中已經存在,我們把這一項在數組中干掉 // // _this.splice(i, 1); [后面項移位,消耗性能] // _this[i] = _this[_this.length - 1]; // _this.length--; // i--; // continue; // } // obj[item] = true; // } // obj = null; // return _this; // }; //=>雙循環(不推薦) // Array.prototype.myUnique = function () { // let _this = [...this]; // for (let i = 0; i < _this.length; i++) { // let item = _this[i]; // //=>每一次迭代到ITEM后,都拿其后面的內容和它進行比較(出現和當前項相同的,我們就在數組中把其干掉) // for (let j = i + 1; j < _this.length; j++) { // if (item === _this[j]) { // //=>刪除索引J這一項 // _this[j] = _this[_this.length - 1]; // _this.length--; // j--; // } // } // } // return _this; // }; //=>indexOf:獲取當前項在數組中第一次出現位置的索引,也能判斷是否存在這一項(不存在獲取的索引是-1),這個方法是不兼容IE6~8的 // Array.prototype.myUnique = function () { // let _this = [...this]; // //=>依次迭代數組中的每一項,驗證當前項在數組中是否存在(不是和整個數組比較是否存在,而是和當前項的后面項比較是否存在=>類似于雙FOR),存在把當前項干掉 // for (let i = 0; i < _this.length; i++) { // let item = _this[i], // nextAry = _this.slice(i + 1); // if (nextAry.indexOf(item) > -1) { // _this[i] = _this[_this.length - 1]; // _this.length--; // i--; // } // } // return _this; // }; //=>排序后相鄰去除法 //先把數組進行排序,驗證當前項和后一項是否相同,如果不相同,說明沒有重復,我們把著于相提取出來保存即可 // Array.prototype.myUnique = function () { // let _this = [], // ary = this.slice(0).sort((a, b) => a - b); // for (let i = 0; i < ary.length; i++) { // let item = ary[i], // next = ary[i + 1]; // if (item !== next) { // _this.push(item); // } // } // return _this; // }; let ary = [1, 2, 3, 2, 3, 4, 3, 2, 2, 2, 2, 3, 4, 5, 6, 7, 4, 1, 3, 2]; let uniqueAry = ary.myUnique(); console.log(uniqueAry); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看