二分查找法
<script> function m(num, list) { var low = 0; var height = list.length - 1; while (low <= height) { var midder = parseInt((low + height) / 2) if (num == list[midder]) { return midder; } else if (num > list[midder]) { low = midder + 1 } else { height = midder - 1 } } return -1; } var s = m(16, [1, 2, 3, 4, 5, 6, 7, 8,9,10,11,12, 13, 14, 15, 16]); console.log(s); </script>
本文来自博客园,作者:刘先生的爱心博客,转载请注明原文链接:https://www.cnblogs.com/liu521125/p/17849015.html
一点一滴记录着学习html5 css3 和js 的时光