Skip to content

Commit

Permalink
add notice.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Yi-love committed Jun 16, 2016
1 parent 99b36b1 commit 59e8bcd
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_site
59 changes: 59 additions & 0 deletions _posts/2016-06-15-16-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
layout: page
title: 2016年Js知识点
categories: [笔记]
tags: [2016,JS知识,个人,前端]
---

自己平时收集的JS小知识点。

### 1. void 0
```js
typeof void 0 //"undefined"
undefined === void 0 //true
undefined == void 0 //true
null == void 0 //true
"undefined" == void 0 //false
```

### 2. null
`undefined` 表示未定义 ; `null`表示值为空。

```js
typeof null //"object"
undefined == null //true
undefined === null //false
```

### 3. 正负无穷大
```js
Infinity //Infinity
1.7976931348623157E+1030899 //Infinity
-1.7976931348623157E+1030899 //-Infinity
```

### 4. Fisher-Yates shuffle 洗牌算法
洗牌算法: [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).

```js
var shuffle = function(arr , n) {
if (n == null) n = Infinity;
var n = Math.max(Math.min(n, arr.length), 0);
var last = arr.length - 1;
for (var index = 0; index < n; index++) {
var rand = random(index, last);
var temp = arr[index];
arr[index] = arr[rand];
arr[rand] = temp;
}
return arr.slice(0, n);
};

var random = function(min, max) {
if (max == null) {
max = min;
min = 0;
}
return min + Math.floor(Math.random() * (max - min + 1));
};
```

0 comments on commit 59e8bcd

Please sign in to comment.