This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 二分查找 | |
* @param {Array} array - 有序数组 | |
* @param {Number} value - 查找目标值 | |
*/ | |
function binarySearch (array, value) { | |
let index = 0; | |
let left = 0; | |
let right = array.length - 1; | |
while (left < right) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 斐波那契数列 | |
* of ES6 | |
*/ | |
function fibonacci () { | |
let fn1 = 0; | |
let fn2 = 1; | |
let next = reset => { | |
if (reset) { | |
fn1 = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 在指定范围内获取随机整数 | |
* @param {Number} min - 最小值 | |
* @param {Number} max - 最大值 | |
* @return {Number} | |
*/ | |
function getRandomIntInRange (min, max) { | |
return Math.floor(Math.random() * (max - min + 1) + min); | |
} |
NewerOlder