Home >Web Front-end >JS Tutorial >JavaScript algorithm learning implementation code_javascript skills

JavaScript algorithm learning implementation code_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:07:541007browse

[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<script> var len = 100000; var i; var arr = []; for(i=0; i<len; ++i) { arr[i] = i; //造10万条数据 } var num1 = arr.splice(8000,1); //随机取走两条数据 var num2 = arr.splice(3000,1); var arr2 = []; var startTime = +new Date(); //开始时间 var result = []; //保存抽取出来的数 for(i=0; i<len; ++i) { arr2[arr[i]] = arr[i]; //把剩下的各元素放入一个新数组 } for(i=0; i<len; ++i) { if(typeof arr2[i] == 'undefined') { result.push(i); } } var endTime = +new Date(); alert(endTime - startTime); //计算排序时间 alert(result); //得到抽走的数字 </script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn