Skip to content

Instantly share code, notes, and snippets.

@jikeytang
Created July 28, 2014 23:43
Show Gist options
  • Save jikeytang/2520829f1cf04f28fde6 to your computer and use it in GitHub Desktop.
Save jikeytang/2520829f1cf04f28fde6 to your computer and use it in GitHub Desktop.
[ Javascript ] - 20140729-题目1
输出在一个范围内,所有2进制位为1的数。
比如:
[0,2] -> 1 对应2进制 (1)
[1,3] -> 1,3 对应2进制 (1, 11)
[2,5] -> 3 对应2进制 (11)
PS:
1. 回复时注意加上下面这句话,才会有语法高亮或格式缩进。
```javascript
// you code
```
2. 粘贴代码时请使用shift+tab,缩进前面的空白。
@heqing0712
Copy link

function a(min,max){
    var arr = [];
    while (min <= max) {
        (/^1+$/g).test((min++).toString(2)) && arr.push(min - 1);
    }
    return arr;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment