0216tool_xiaoye
Version:
叶永洁自定义工具函数库
32 lines (29 loc) • 1.02 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>数组去重</title>
</head>
<body>
<script src="../dist/yeyongjie.js"></script>
<script>
/**
* 1. 理解:
根据当前数组产生一个去除重复元素后的新数组
如: [2, 3, 2, 7, 6, 7] ==> [2, 3, 7, 6]
2. 实现:
方法1: 利用forEach()和indexOf()
说明: 本质是双重遍历, 效率差些
方法2: 利用forEach() + 对象容器
说明: 只需一重遍历, 效率高些
方法3: 利用ES6语法: from + Set 或者 ... + Set
说明: 编码简洁
*/
const arr = [2,4,5,7,2,5,10]
console.log(xiaoYe.unique1(arr))
console.log(xiaoYe.unique2(arr))
console.log(xiaoYe.unique3(arr))
</script>
</body>
</html>