- 浏览: 403311 次
- 性别:
- 来自: 上海
-
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
It is a common practice to make sure that each element of an array or an collection should be unqiue, application scenario including in the divide and conquer step, you may want to merge some array from different sub-step but you want to make sure no duplicate ends up in the list.
below shows the code and test code to show you a common technique to make that happen.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript" src="../unit.js"></script> <style type="text/css"> #results li.pass {color:Green} #results li.fail {color:Red} </style> </head> <body> <div id="test"> <b>Hello</b>, I'm a ninja </div> <div id="test2"></div> <script type="text/javascript"> (function () { var run = 0; this.unique = function (array) { var ret = []; run++; for (var i = 0, length = array.length; i < length; i++) { var elem = array[i]; if (elem.uniqueID !== run) { elem.uniqueID = run; ret.push(array[i]); } } return ret; }; })(); window.onload = function () { test("Test filter uniqueness", function () { var divs2 = document.getElementsByTagName("div"); var divs = unique(document.getElementsByTagName("div")); assert(divs.length === 2, "No duplicates removed."); var body = unique([document.body, document.body]); assert(body.length === 1, "Body duplicate removed."); }); }; </script> <ul id="results"></ul> </body> </html>
the solution is basically assign some property to an element, and check if the new testing element has the matching unique id, if not, reassign the uniqueID; and the key is function will use a different ID each time the method to remove duplicate is called.
发表评论
-
javascript - trick to cross browser DOM ready event
2012-08-24 08:23 939the "ready" event ... -
javascript - trick to simulate mouseenter and mouseleave
2012-08-23 08:31 2259Previously we discussed javasc ... -
javascript - trick to simulate the change event
2012-08-22 08:51 1680In the previous discussion a ... -
javascript - trick to simulate bubbling submit event
2012-08-22 08:03 912In the previous discussion abou ... -
javascript - trick to implement bubbling submit event
2012-08-23 07:55 713Following up to the javascrip ... -
javascript - trick to detect bubbling supportability
2012-08-20 22:22 982Event delegation is oe of the b ... -
javascript - trigger event and custom events
2012-08-20 21:58 2088In the previous post - javascri ... -
javascript - trick to handlers management
2012-08-20 08:19 1040We have discussed "javascr ... -
javascript - trick to centralized store
2012-08-20 07:52 829For a number of reasons it's ... -
javascript - trick to fix the event object
2012-08-20 07:47 890Many browsers, especially In ... -
javascript - tricks to deal with colors
2012-08-15 08:34 778There are a couple of ways to r ... -
javascript - trick to manipulate the opacity
2012-08-15 08:26 773All other browsre may have supp ... -
javascript - trick to test visibility of an element
2012-08-15 08:15 529though there is a visible prope ... -
javascript - trick to get and set height and width
2012-08-15 08:05 554when looking at properties t ... -
javascript - trick to set/get attributes that expects px values
2012-08-16 11:00 525When setting a number into a ... -
javascript - trick to get and set CSS style
2012-08-16 11:00 756while it will not be so much tr ... -
javascript - trick to normalize href for IE
2012-08-16 10:59 548IE is again the only browser th ... -
javascript - trick IE form and its expando attribute
2012-08-16 10:59 1051there is a known issue that if ... -
javascript expando and attributes
2012-08-14 08:15 1050expando is something like this ... -
javascript - trick to getText and setText
2012-08-14 07:40 1157it is not as simple as you thin ...
相关推荐
**前端开源库-es-object-assign** 是一个针对JavaScript编程中的对象合并问题的开源库,它在ES2015(也称为ES6)环境中提供了一种友好的解决方案。在JavaScript中,对象是引用类型,因此直接复制对象时,只会复制...
`reapp-object-assign-master`这个压缩包文件名表明它是`reapp-object-assign`项目的主分支代码,通常包含了项目的源代码、测试文件、文档以及可能的配置文件。开发者可以下载这个压缩包,解压后查看源码,了解其...
《深入理解JavaScript中的Object.assign与对象合并》 在JavaScript中,`Object.assign`是一个非常实用的方法,用于合并多个源对象的属性到一个目标对象中。这个功能在开发过程中经常被用到,特别是在处理数据合并、...
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
react-assign 不需要任何引用就可以更新 ReactJS 状态。react-assign 是轻量级 React 类状态更新快捷方式,不需要专门定义一个函数处理器。常规更新:var React = require('react'); React.createClass({ ...
Shoulda- assign_to ( )在2.0.0版中删除了assign_to匹配器。 我们非常想念它,足以把它带回来。 该gem重新添加了assign_to匹配器,并通过引用包括了所有其他的shoulda-matchers就像它被无情地销毁之前一样。 示例...
aws-ec2-assign-elastic-ip, 自动分配弹性ip到 AWS EC2自动缩放组实例 aws-ec2-assign-elastic-ip 自动分配弹性ip到 AWS EC2实例。 在自动缩放组中,这可以能非常好,你需要通信ip第三方系统。应该在应该分配有弹性...
$ npm install --save deep-assign 用法 var deepAssign = require ( 'deep-assign' ) ; deepAssign ( { a : { b : 0 } } , { a : { b : 1 , c : 2 } } , { a : { c : 3 } } ) ; //=> {a: {b: 1, c: 3}} deepAssign...
安装ember install ember-assign-polyfill用法import Ember from 'ember' ;var a = { first : 'Robert' } ;var b = { last : 'Wagner' } ;var c = { company : 'Ship Shape' } ;Ember . assign ( a , b , c ) ; // a...
递归分配只是递归分配用npm i recursive-assign const extend = require ( 'recursive-assign' )const { equal } = require ( 'assert' )let a = { x : '3' , y : true , z : { ff : 'as' , gg : 0 , hh : { kl : '...
【Java-Assign-Chap-1-to-67:JavaScript 分配】这个压缩包文件主要涵盖了JavaScript编程语言的基础到高级主题,可能包括了从第1章到第67章的学习资料,涉及广泛的知识点。JavaScript是一种重要的客户端脚本语言,常...
Section 4.5.2.4.2 Assign Cable SOP* State is incorrect. Passive cables never respond on SOP” per USB PD. The change is to remove the sentence “If two eMarkers are powered at the same time in a ...
var assign = require ( 'filter-object-assign' )target = assign ( target , sources . . . , filterFunction ) 大多数实现来自Sindre Sorhus的 。安装npm install filter-object-assign --save例子 var assign =...
自动作者分配 GitHub动作:自动分配拉取请求作者。... assign-author : runs-on : ubuntu-latest steps : - uses : toshimaru/auto-author-assign@v1.3.0 with : repo-token : " ${{ secrets.GITHUB_
npm install deep-object-assign-with-reduce 或者 yarn add deep-object-assign-with-reduce 变更日志 3.0.0 - 删除节点 8 和 9 支持。 如果您希望使用旧版本的 Node,请使用2.x 2.0.0 - 放弃了对 IE 11 的支持...
NX二次开发UF_CLONE_ask_assign_default_project 函数介绍,Ufun提供了一系列丰富的 API 函数,可以帮助用户实现自动化、定制化和扩展 NX 软件的功能。无论您是从事机械设计、制造、模具设计、逆向工程、CAE 分析等...
NX二次开发UF_CLONE_set_assign_default_project 函数介绍,Ufun提供了一系列丰富的 API 函数,可以帮助用户实现自动化、定制化和扩展 NX 软件的功能。无论您是从事机械设计、制造、模具设计、逆向工程、CAE 分析等...
Babel 的 Object.assign 插件 用扩展助手替换Object.assign() Babel 插件。 当您想要在没有本机支持的情况下扩展浏览器中的对象时,有助于减少对额外 polyfill 或库的需求。 感谢@sebmck 的实现。 用法 而不是使用...
例如,对于 JavaScript,它可以处理箭头函数表达式;对于 Java,它会考虑静态方法调用等。 为了充分利用这个插件,你需要了解如何自定义其行为。可以通过修改 Vim 脚本(即 Vimscript)来设置特定的语言规则,或者...
NX二次开发UF_DISP_assign_material 函数介绍,Ufun提供了一系列丰富的 API 函数,可以帮助用户实现自动化、定制化和扩展 NX 软件的功能。无论您是从事机械设计、制造、模具设计、逆向工程、CAE 分析等领域的专业...