专栏名称: 程序员大咖
为程序员提供最优质的博文、最精彩的讨论、最实用的开发资源;提供最新最全的编程学习资料:PHP、Objective-C、Java、Swift、C/C++函数库、.NET Framework类库、J2SE API等等。并不定期奉送各种福利。
目录
今天看啥  ›  专栏  ›  程序员大咖

JavaScript数组去重

程序员大咖  · 公众号  · 程序员  · 2017-04-26 19:19
    

文章预览

来自:AnnatarHe's blog 链接:https://annatarhe.github.io/2016/12/21/some-diff-filter-method.html 最近写了一道数组去重的题,手抖,紧张,没写好。后来写了一会儿觉得还挺有意义的。现在做一下记录 Test case 测试用例如下 import test from 'ava'   import unique from '../src/unique'   test( '[1,1,2] should return [1, 2]' , t => {       t.plan( 3 )       const src = [ 1 , 1 , 2 ]       const result = unique(src)       t.is(result.length, 2 )       t.is(result[ 0 ], 1 )       t.is(result[ 1 ], 2 )   })   test( '[1, 1, "1"] should return [1, "1"]' , t => {       t.plan( 4 )       const src = [ 1 , 1 , '1' ]       const result = unique(src)       t.is(result.length, 2 )       t.is(result.indexOf( 1 ), 0 )       t.is(typeof result[ 1 ], 'string' ) ………………………………

原文地址:访问原文地址
快照地址: 访问文章快照
总结与预览地址:访问总结与预览