object, save the push to a new array and record the save in a object[arrayitem]=1 wayfunction removeDuplicatedItem2 (AR) { var tmp = {}, = []; for (var i = 0, j = ar.length; I ) { if (! Tmp[ar[i]]) { = 1; Ret.push (Ar[i]); } } return ret;}method Three : Array subscript judgment method, iterate the array, use IndexOf to determine whether the value of the element is equal to the current index, such as equal to joinfunction removeDuplicate
vara=[1,2,3,4,4]; varb=[]; varC={};//the IndexOf property returns 1 for a non-existent element, otherwise the specified position of the character is returned.//For (i in a) {//if (B.indexof (A[i]) ==-1) {//B.push (A[i])//// }// }//method Two creates an empty variable by judging whether the variable has an assigned Boolean value to the variable for(varI=0; i){ if(!C[a[i]]) {C[a[i]]=true; B.push (A[i]); }} console.log (b);An array of front-end interviews to
= 1; I This. length; i++){5 if( This[i]!== res[res.length-1]){6Res.push ( This[i]);7 }8 }9 returnRes;Ten } One vararr = [1, ' A ', ' a ', ' B ', ' d ', ' e ', ' e ', 1, 0]; AConsole.log (Arr.unique ());The second method also has some limitations because it is sorted before going to heavy, so the final return of the de-weight result is also sorted. This method is not available if the order of the array is not changed to be heavy.The third method of thinking:1. Create a new array to hold t
use a self-executing anonymous function to do a traversal of the array, because Newarr is a global variable, after execution will not be destroyed, but return to go out, the final printing results are [1,2,3,4];This is es5 the most unadorned writing, can be said to be a "ancient writing" bar, ES6 has a structure called set, it is born with the cross-specific, that is sure there will not be repeated, see a piece of code to know.1 var s=New Set (arr); // the result is set{1,2,3,4} 2 v
indexof.To determine the efficiency of these three methods, I made a test program, generated an array of 10000-length random numbers, and then used several methods to test the execution time. The results show that the second method is much faster than the other two methods. However, the memory footprint should be the second method more, because a hash table. This is the so-called space change time. This is the test page, you can also go to see.The fourth method:Array.prototype.unique4 = functio
and cons, how can we as far as possible to turn the harm into profit? This requires us to exchange links before the exchange of links to the site to do some analysis and examination. How to weigh it? Below Chongqing seo on how to exchange links to talk about their own experience, for you to sum up the following points.
First, check whether the site has the right to drop or be K
This is the first step in exchanging links that you need to check. If t
Today, the bath to think of an interesting question, using JS to the array to go heavy, I think four ways, although today's task is not completed, 5555:Not much to say, PO code:Method One: Simple cycle to weightArray.prototype.unique1 = function () {var temp = [];for (var i=0; i if (Temp.indexof (this[i]) = =-1) {Temp.push (This[i]);}}return temp;}Method two: After using sorting, the method to compare in turnArray.prototype.unique2 = function () {This.sort ();var temp = [This[0]];var j = 0;For (
[Small project] luggage (unlock and weigh Bluetooth), luggage weighing
1 #include Main
1 #ifndef __HX711_H__ 2 #define __HX711_H__ 3 4 5 #include HX711.H
1 #include "HX711.h" 2 3 unsigned long ReadCount(void) 4 { 5 unsigned long Count; 6 unsigned char i; 7 ADSK=0; 8 Count=0; 9 while(ADDO); 10 for (i=0;iHX711.c
Due to the limited conditions of raw materials and relatively lazy individuals, digital tubes are not used to display the weight, nor m
ofO_obj'Inputlen'=0. SET Property ofO_obj'PortOpen'=1.EndForm."Prm_open_portread interface data: Because the interface has a cache, each time the read is stripped of the first 20 of the data and every time the data read is not complete, so you need to connect multiple read data, and then intercept****************************************************************************FORMPrm_read_portchangingE_output. DATA: Wa_bufferTYPEI, IndeTYPEi. Do - Times. Inde= Inde +1. GET Property ofO_obj'In
1. Iterate through the original array and the new array. New an array that holds the unique elements that have been traversed.function Uniquearr (list) {var newarr= [list[0]];for (Var i=1;ivar isrepeat = false;for (Var j=0;jif (list[i] = = Newarr[j]) {isrepeat= true;Break}}if (!isrepeat) {Newarr.push (List[i]);}}return NEWARR;}var arr=[' A ', ' B ', ' C ', ' A ', ' B '];Uniquearr (arr); Output:["A", "B", "C"]2, by first sorting, and then compared with the adjacent elements to the weight (after s
field is empty (null), it is not recommended to Jianjian the word index.Please remember that there must be a business need to build the index. For example, in a commodity table, we often have to query according to name, if there is no index, query speed is very slow, then we need to build an index. However, in project development, it is not necessary to index a number if it is not often queried according to the product number.Finally, the index is to pay a price, nothing to build, at the same t
An array is defined first, and the following three methods are used to manipulate the array// define an array var arr=[' js ', ' js ', ' JS ', ' html ', ' JS ', ' Java ', ' C + + ', ' css ', ' HTML5 ', ' C # ', ' C # ', ' CSS ', ' html ', ' JS '];1. The first method1array.prototype.unique1=function(){2 for(vari=0;i This. length-1;i++){3 for(varj=1;j This. length;j++){4 if( This[i]== This[i+J]) {5 This. Splice (i+j,1);6j--;7 }8 }9 }T
Jonathan Sagorin A full disclosure of Enterprise Java™beans (EJB) transactions in the last part of the three-part series. Explore the challenges and additional implementation and configuration options associated with container management
Except for the smallest enterprises, all organizations have security audits for certain levels of servers. Regardless of the number of Logon failures, security file access, file deletion, activity directory modification, or other information it
Implementation ideas: Create a new array, iterate through the incoming array, the value is not added to the new array in the new array; Note: The method of judging whether the value is in the array "IndexOf" is the ECMAScript5 method, IE8 the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.