[Underscore.js]よく使いそうなモジュールまとめてみた


# Underscore.jsってなに

標準のJavaScriptに無い便利なモジュールがたくさん入っています。Backbone.jsが標準で使ってるやつです。

# サンプル

[shuffle](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAANiaSkWfe4XrTQQAAE0EAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7Pjg5fjg6zjg7zjg4jkvZzjgaPjgabjgb/jgb7jgZfjgZ/imaoifSwiY29kZSI6eyJodG1sIjp7InR5cGUiOiJodG1sIiwidmFsdWUiOiI8IURPQ1RZUEUgaHRtbD5cbiBcbjxodG1sPlxuICAgIDxoZWFkPlxuICAgICAgICA8bWV0YSBjaGFyc2V0PVwiVVRGLThcIiAvPlxuICAgICAgICA8bWV0YSBuYW1lPVwidmlld3BvcnRcIiBjb250ZW50PVwid2lkdGg9ZGV2aWNlLXdpZHRoLCB1c2VyLXNjYWxhYmxlPW5vXCIgLz5cbiAgICAgICAgPG1ldGEgbmFtZT1cImFwcGxlLW1vYmlsZS13ZWItYXBwLWNhcGFibGVcIiBjb250ZW50PVwieWVzXCIgLz5cbiBcbiAgICAgICAgPHRpdGxlPiR7dGl0bGV9PC90aXRsZT5cbiAgICAgICAgPG1ldGEgbmFtZT1cImRlc2NyaXB0aW9uXCIgY29udGVudD1cIiR7ZGVzY3JpcHRpb259XCIgLz5cbiAgICAgICAgPHN0eWxlPiR7c3R5bGV9PC9zdHlsZT5cbiAgICAgICAgXG4gICAgICAgIDxzY3JpcHQgc3JjPVwiaHR0cHM6Ly9jZG4ucmF3Z2l0LmNvbS9qYXNoa2VuYXMvdW5kZXJzY29yZS9hZmQ0NzM2YTFiNjRjMTAwN2ZhOTQwZTE5M2U4ODgwZGRlM2VlNzRmL3VuZGVyc2NvcmUuanNcIj48L3NjcmlwdD5cbiAgICAgICAgPHNjcmlwdD4ke3NjcmlwdH08L3NjcmlwdD5cblxuICAgIDwvaGVhZD5cbiAgICA8Ym9keT5cbiAgICA8L2JvZHk+XG48L2h0bWw+In0sInN0eWxlIjp7InR5cGUiOiJjc3MiLCJ2YWx1ZSI6ImJvZHkge1xuICAgIGJhY2tncm91bmQtY29sb3I6IFwiI2VlZVwiO1xufSJ9LCJzY3JpcHQiOnsidHlwZSI6ImphdmFzY3JpcHQiLCJ2YWx1ZSI6Ii8qXG4gKiBVbmRlcnNjb3JlLmpzIOOCteODs+ODl+ODq1xuICovXG5cbi8vIOW3puOBruOCs+ODs+OCveODvOODq+OBjOOAgeS/neWtmOOBmeOCi+W6puOBq+OCt+ODo+ODg+ODleODq+OBleOCjOOBpuOCi1xudmFyIHNodWZmbGVBcnJheSA9IF8uc2h1ZmZsZShbMSwyLDMsNCw1XSk7XG5jb25zb2xlLmRpcihzaHVmZmxlQXJyYXkpO1xuIn19fVBLAQIUAAoAAAAAANiaSkWfe4XrTQQAAE0EAAAEAAAAAAAAAAAAAAAAAAAAAABkYXRhUEsFBgAAAAABAAEAMgAAAG8EAAAAAA==)

```js
var shuffleArray = _.shuffle([1,2,3,4,5]);
console.dir(shuffleArray);
```

[shuffle別の書き方](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAAMaaSkVe2pc9ggQAAIIEAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7Pjg5fjg6zjg7zjg4jkvZzjgaPjgabjgb/jgb7jgZfjgZ/imaoifSwiY29kZSI6eyJodG1sIjp7InR5cGUiOiJodG1sIiwidmFsdWUiOiI8IURPQ1RZUEUgaHRtbD5cbiBcbj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5Yil44Gu5pu444GN5pa5XG4vLyDjgZPjga7mm7jjgY3mlrnjgaDjgajjgIHnhKHpp4TjgavlpInmlbDkvZzjgonjgarjgY/jgabjgYTjgYTjga1cbmNvbnNvbGUuZGlyKF8oWzEsMiwzLDQsNV0pLnNodWZmbGUoKSk7XG4ifX19UEsBAhQACgAAAAAAxppKRV7alz2CBAAAggQAAAQAAAAAAAAAAAAAAAAAAAAAAGRhdGFQSwUGAAAAAAEAAQAyAAAApAQAAAAA)

```js
console.dir(_([1,2,3,4,5]).shuffle());
```

[each](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAAKuaSkXGGwc3SgUAAEoFAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7Pjg5fjg6zjg7zjg4jkvZzjgaPjgabjgb/jgb7jgZfjgZ/imaoifSwiY29kZSI6eyJodG1sIjp7InR5cGUiOiJodG1sIiwidmFsdWUiOiI8IURPQ1RZUEUgaHRtbD5cbiBcbjxodG1sPlxuICAgIDxoZWFkPlxuICAgICAgICA8bWV0YSBjaGFyc2V0PVwiVVRGLThcIiAvPlxuICAgICAgICA8bWV0YSBuYW1lPVwidmlld3BvcnRcIiBjb250ZW50PVwid2lkdGg9ZGV2aWNlLXdpZHRoLCB1c2VyLXNjYWxhYmxlPW5vXCIgLz5cbiAgICAgICAgPG1ldGEgbmFtZT1cImFwcGxlLW1vYmlsZS13ZWItYXBwLWNhcGFibGVcIiBjb250ZW50PVwieWVzXCIgLz5cbiBcbiAgICAgICAgPHRpdGxlPiR7dGl0bGV9PC90aXRsZT5cbiAgICAgICAgPG1ldGEgbmFtZT1cImRlc2NyaXB0aW9uXCIgY29udGVudD1cIiR7ZGVzY3JpcHRpb259XCIgLz5cbiAgICAgICAg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iJ9fX1QSwECFAAKAAAAAACrmkpFxhsHN0oFAABKBQAABAAAAAAAAAAAAAAAAAAAAAAAZGF0YVBLBQYAAAAAAQABADIAAABsBQAAAAA=)

```js
_(_([
    {name: "A", power: 10},
    {name: "B", power: 20},
    {name: "C", power: 15},
]).shuffle()).each(function (l) {
    console.log(l.name, l.power);
});
```

```js
_.each(_.shuffle([
    {name: "A", power: 10},
    {name: "B", power: 20},
    {name: "C", power: 15},
]), function (l) {
	console.log(l.name, l.power);
});
```

[map](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAAJqaSkU9EqRubAUAAGwFAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7Pjg5fjg6zjg7zjg4jkvZzjgaPjgabjgb/jgb7jgZfjgZ/imaoifSwiY29kZSI6eyJodG1sIjp7InR5cGUiOiJodG1sIiwidmFsdWUiOiI8IURPQ1RZUEUgaHRtbD5cbiBcbjxodG1sPlxuICAgIDxoZWFkPlxuICAgICAgICA8bWV0YSBjaGFyc2V0PVwiVVRGLThcIiAvPlxuICAgICAgICA8bWV0YSBuYW1lPVwidmlld3BvcnRcIiBjb250ZW50PVwid2lkdGg9ZGV2aWNlLXdpZHRoLCB1c2VyLXNjYWxhYmxlPW5vXCIgLz5cbiAgICAgICAgPG1ldGEgbmFtZT1cImFwcGxlLW1vYmlsZS13ZWItYXBwLWNhcGFibGVcIiBjb250ZW50PVwieWVzXCIgLz5cbiBcbiAgICAgICAgPHRpdGxlPiR7dGl0bGV9PC90aXRsZT5cbiAgICAgICAgPG1ldGEgbmFtZT1cImRlc2NyaXB0aW9uXCIgY29udGVudD1cIiR7ZGVzY3JpcHRpb259XCIgLz5cbiAgICAgICAgPHN0eWxlPiR7c3R5bGV9PC9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S5kaXIobWFwRGF0YSk7XG4ifX19UEsBAhQACgAAAAAAmppKRT0SpG5sBQAAbAUAAAQAAAAAAAAAAAAAAAAAAAAAAGRhdGFQSwUGAAAAAAEAAQAyAAAAjgUAAAAA)

```js
console.dir(_([1,2,3,4,5]).map(function (l) {
    return l+5; // +5した値で新たに配列を作成
}));
```

```js
console.dir(_.map([1,2,3,4,5], function (l) {
	return l+5;
}));
```

[range](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAAGm2SkW+fcrfaAQAAGgEAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7Pjg5fjg6zjg7zjg4jkvZzjgaPjgabjgb/jgb7jgZfjgZ/imaoifSwiY29kZSI6eyJodG1sIjp7InR5cGUiOiJodG1sIiwidmFsdWUiOiI8IURPQ1RZUEUgaHRtbD5cbiBcbjxodG1sPlxuICAgIDxoZWFkPlxuICAgICAgICA8bWV0YSBjaGFyc2V0PVwiVVRGLThcIiAvPlxuICAgICAgICA8bWV0YSBuYW1lPVwidmlld3BvcnRcIiBjb250ZW50PVwid2lkdGg9ZGV2aWNlLXdpZHRoLCB1c2VyLXNjYWxhYmxlPW5vXCIgLz5cbiAgICAgICAgPG1ldGEgbmFtZT1cImFwcGxlLW1vYmlsZS13ZWItYXBwLWNhcGFibGVcIiBjb250ZW50PVwieWVzXCIgLz5cbiBcbiAgICAgICAgPHRpdGxlPiR7dGl0bGV9PC90aXRsZT5cbiAgICAgICAgPG1ldGEgbmFtZT1cImRlc2NyaXB0aW9uXCIgY29udGVudD1cIiR7ZGVzY3JpcHRpb259XCIgLz5cbiAgICAgICAgPHN0eWxlPiR7c3R5bGV9PC9zdHlsZT5cbiAgICAgICAgXG4gICAgICAgIDxzY3JpcHQgc3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KiBVbmRlcnNjb3JlLmpzIOOCteODs+ODl+ODq1xuICovXG5cbi8vIHJhbmRvbeOBr+ODqeODs+ODgOODoOOBquWApFxuLy8gc2F2ZeOBmeOCi+aXheOBq+WApOOBjOOBi+OCj+OBo+OBpuOBhOOCi1xuY29uc29sZS5sb2coXy5yYW5kb20oLTEwMCwgMTAwKSk7XG4ifX19UEsBAhQACgAAAAAAr7ZKRYNv1sooBAAAKAQAAAQAAAAAAAAAAAAAAAAAAAAAAGRhdGFQSwUGAAAAAAEAAQAyAAAASgQAAAAA)

```js
console.log(_.random(-100, 100)); // -100から100の間のランダムな値
```

[find](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAAI2aSkUBiDq5YwQAAGMEAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7Pjg5fjg6zjg7zjg4jkvZzjgaPjgabjgb/jgb7jgZfjgZ/imaoifSwiY29kZSI6eyJodG1sIjp7InR5cGUiOiJodG1sIiwidmFsdWUiOiI8IURPQ1RZUEUgaHRtbD5cbiBcbjxodG1sPlxuICAgIDxoZWFkPlxuICAgICAgICA8bWV0YSBjaGFyc2V0PVwiVVRGLThcIiAvPlxuICAgICAgICA8bWV0YSBuYW1lPVwidmlld3BvcnRcIiBjb250ZW50PVwid2lkdGg9ZGV2aWNlLXdpZHRoLCB1c2VyLXNjYWxhYmxlPW5vXCIgLz5cbiAgICAgICAgPG1ldGEgbmFtZT1cImFwcGxlLW1vYmlsZS13ZWItYXBwLWNhcGFibGVcIiBjb250ZW50PVwieWVzXCIgLz5cbiBcbiAgICAgICAgPHRpdGxlPiR7dGl0bGV9PC90aXRsZT5cbiAgICAgICAgPG1ldGEgbmFtZT1cImRlc2NyaXB0aW9uXCIgY29udGVudD1cIiR7ZGVzY3JpcHRpb259XCIgLz5cbiAgICAgICAgPHN0eWxlPiR7c3R5bGV9PC9zdHlsZT5cbiAgICAgICAgXG4gICAgICAgIDxzY3JpcHQgc3JjPVwiaHR0cHM6Ly9jZG4ucmF3Z2l0LmNvbS9qYXNoa2VuYXMvdW5kZXJzY29yZS9hZmQ0NzM2YTFiNjRjMTAwN2ZhOTQwZTE5M2U4ODgwZGRlM2VlNzRmL3VuZGVyc2NvcmUuanNcIj48L3NjcmlwdD5cbiAgICAgICAgPHNjcmlwdD4ke3NjcmlwdH08L3NjcmlwdD5cblxuICAgIDwvaGVhZD5cbiAgICA8Ym9keT5cbiAgICA8L2JvZHk+XG48L2h0bWw+In0sInN0eWxlIjp7InR5cGUiOiJjc3MiLCJ2YWx1ZSI6ImJvZHkge1xuICAgIGJhY2tncm91bmQtY29sb3I6IFwiI2VlZVwiO1xufSJ9LCJzY3JpcHQiOnsidHlwZSI6ImphdmFzY3JpcHQiLCJ2YWx1ZSI6Ii8qXG4gKiBVbmRlcnNjb3JlLmpzIOOCteODs+ODl+ODq1xuICovXG5cbi8vIGZpbmTjga/mnaHku7bjgpJyZXR1cm7jgZnjgotcbmNvbnNvbGUubG9nKF8oWzEsMiwzLDQsNV0pLmZpbmQoZnVuY3Rpb24gKGwpIHtcbiAgICByZXR1cm4gbCA+IDI7IC8vIDLjgojjgorlpKfjgY3jgarmlbDjgafjgIHmnIDliJ3jgavjg57jg4Pjg4HjgZfjgZ/mlbDjgpLov5TjgZlcbn0pKTtcbiJ9fX1QSwECFAAKAAAAAACNmkpFAYg6uWMEAABjBAAABAAAAAAAAAAAAAAAAAAAAAAAZGF0YVBLBQYAAAAAAQABADIAAACFBAAAAAA=)

```js
console.log(_([1,2,3,4,5]).find(function (l) {
    return l > 2; // 2より大きな数で、最初にマッチした数を返す
}));
```

```js
console.log(_.find([1,2,3,4,5], function (l) {
    return l > 2;
}));
```

[filter](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAA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0bWw+In0sInN0eWxlIjp7InR5cGUiOiJjc3MiLCJ2YWx1ZSI6ImJvZHkge1xuICAgIGJhY2tncm91bmQtY29sb3I6IFwiI2VlZVwiO1xufSJ9LCJzY3JpcHQiOnsidHlwZSI6ImphdmFzY3JpcHQiLCJ2YWx1ZSI6Ii8qXG4gKiBVbmRlcnNjb3JlLmpzIOOCteODs+ODl+ODq1xuICovXG5cbi8vIGZpbHRlcuOCguadoeS7tuOCknJldHVybuOBmeOCi1xuY29uc29sZS5kaXIoXyhbMSwyLDMsNCw1XSkuZmlsdGVyKGZ1bmN0aW9uIChsKSB7XG4gICAgcmV0dXJuIGwgPiAyOyAvLyAy44KI44KK5aSn44GN44Gq5pWw5YWo44Gm44CB44Oe44OD44OB44GX44Gf5pWw44KS6L+U44GZXG59KSk7XG4ifX19UEsBAhQACgAAAAAAdppKRfq4ay9hBAAAYQQAAAQAAAAAAAAAAAAAAAAAAAAAAGRhdGFQSwUGAAAAAAEAAQAyAAAAgwQAAAAA)

```js
console.dir(_([1,2,3,4,5]).filter(function (l) {
    return l > 2; // 2より大きな数全て、マッチした数を返す
}));
```

```js
console.dir(_.filter([1,2,3,4,5], function (l) {
    return l > 2;
}));
```

[contains](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAAECaSkXquSrgPgQAAD4EAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7Pjg5fjg6zjg7zjg4jkvZzjgaPjgabjgb/jgb7jgZfjgZ/imaoifSwiY29kZSI6eyJodG1sIjp7InR5cGUiOiJodG1sIiwidmFsdWUiOiI8IURPQ1RZUEUgaHRtbD5cbiBcbjxodG1sPlxuICAgIDxoZWFkPlxuICAgICAgICA8bWV0YSBjaGFyc2V0PVwiVVRGLTh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In19fVBLAQIUAAoAAAAAAECaSkXquSrgPgQAAD4EAAAEAAAAAAAAAAAAAAAAAAAAAABkYXRhUEsFBgAAAAABAAEAMgAAAGAEAAAAAA==)

```js
// containsは、指定したデータが含まれているかどうかを返す
console.log(_([1,3,12,8,9,12,12,9]).contains(12));
```

```js
console.log(_.contains([1,3,12,8,9,12,12,9], 12));
```

[keys](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAAEK1SkW+QXwtPgQAAD4EAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7Pjg5fjg6zjg7zjg4jkvZzjgaPjgabjgb/jgb7jgZfjgZ/imaoifSwiY29kZSI6eyJodG1sIjp7InR5cGUiOiJodG1sIiwidmFsdWUiOiI8IURPQ1RZUEUgaHRtbD5cbiBcbjxodG1sPlxuICAgIDxoZWFkPlxuICAgICAgICA8bWV0YSBjaGFyc2V0PVwiVVRGLThcIiAvPlxuICAgICAgICA8bWV0YSBuYW1lPVwidmlld3BvcnRcIiBjb250ZW50PVwid2lkdGg9ZGV2aWNlLXdpZHRoLCB1c2VyLXNjYWxhYmxlPW5vXCIgLz5cbiAgICAgICAgPG1ldGEgbmFtZT1cImFwcGxlLW1vYmlsZS13ZWItYXBwLWNhcGFibGVcIiBjb250ZW50PVwieWVzXCIgLz5cbiBcbiAgICAgICAgPHRpdGxlPiR7dGl0bGV9PC90aXRsZT5cbiAgICAgICAgPG1ldGEgbmFtZT1cImRlc2NyaXB0aW9uXCIgY29udGVudD1cIiR7ZGVzY3JpcHRpb259XCIgLz5cbiAgICAgICAgPHN0eWxlPiR7c3R5bGV9PC9zdHlsZT5cbiAgICAgICAgXG4gICAgICAgIDxzY3JpcHQgc3JjPVwiaHR0cHM6Ly9jZG4ucmF3Z2l0LmNvbS9qYXNoa2VuYXMvdW5kZXJzY29yZS9hZmQ0NzM2YTFiNjRjMTAwN2ZhOTQwZTE5M2U4ODgwZGRlM2VlNzRmL3VuZGVyc2NvcmUuanNcIj48L3NjcmlwdD5cbiAgICAgICAgPHNjcmlwdD4ke3NjcmlwdH08L3NjcmlwdD5cblxuICAgIDwvaGVhZD5cbiAgICA8Ym9keT5cbiAgICA8L2JvZHk+XG48L2h0bWw+In0sInN0eWxlIjp7InR5cGUiOiJjc3MiLCJ2YWx1ZSI6ImJvZHkge1xuICAgIGJhY2tncm91bmQtY29sb3I6IFwiI2VlZVwiO1xufSJ9LCJzY3JpcHQiOnsidHlwZSI6ImphdmFzY3JpcHQiLCJ2YWx1ZSI6Ii8qXG4gKiBVbmRlcnNjb3JlLmpzIOOCteODs+ODl+ODq1xuICovXG5cbi8vIGtleXPjga/jgIHjgqrjg5bjgrjjgqfjgq/jg4jjga7jg5fjg63jg5Hjg4bjgqPjgpLjgZnjgbnjgabphY3liJfjgaflh7rjgZlcbmNvbnNvbGUubG9nKF8oe1wiYVwiOiAxLCBcImJcIjogMiwgXCJjXCI6IDN9KS5rZXlzKCkpO1xuIn19fVBLAQIUAAoAAAAAAEK1SkW+QXwtPgQAAD4EAAAEAAAAAAAAAAAAAAAAAAAAAABkYXRhUEsFBgAAAAABAAEAMgAAAGAEAAAAAA==)

```js
// keysは、オブジェクトのプロパティをすべて配列で出す
console.log(_({"a": 1, "b": 2, "c": 3}).keys());
```

```js
console.log(_.keys({"a": 1, "b": 2, "c": 3}));
```


[values](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAAJm1SkUEPVWQwgQAAMIEAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7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pzIOOCteODs+ODl+ODq1xuICovXG5cbi8vIHZhbHVlc+OBr+OAgeOCquODluOCuOOCp+OCr+ODiOOBruODl+ODreODkeODhuOCo+OBruWApOOCkuOBmeOBueOBpumFjeWIl+OBp+WHuuOBmVxuLy8ga2V5c+OBr+ODl+ODreODkeODhuOCo+WQjeOAgXZhbHVlc+OBr+ODl+ODreODkeODhuOCo+OBruWApOOCkuWPluOCiuWHuuOBmeOBqOOAgVxuLy8g44K744OD44OI44Go5oCd44GG44Go44KI44GV44Gd44GGXG5jb25zb2xlLmxvZyhfKHtcImFcIjogMSwgXCJiXCI6IDIsIFwiY1wiOiAzfSkudmFsdWVzKCkpO1xuIn19fVBLAQIUAAoAAAAAAJm1SkUEPVWQwgQAAMIEAAAEAAAAAAAAAAAAAAAAAAAAAABkYXRhUEsFBgAAAAABAAEAMgAAAOQEAAAAAA==)

```js
// valuesは、オブジェクトのプロパティの値をすべて配列で出す
console.log(_({"a": 1, "b": 2, "c": 3}).values());
```

```js
console.log(_.values({"a": 1, "b": 2, "c": 3}));
```

[has](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAAMG1SkUzwXQucAQAAHAEAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7Pjg5fjg6zjg7zjg4jkvZzjgaPjgabjgb/jgb7jgZfjgZ/imaoifSwiY29kZSI6eyJodG1sIjp7InR5cGUiOiJodG1sIiwidmFsdWUiOiI8IURPQ1RZUEUgaHRtbD5cbiBcbjxodG1sPlxuICAgIDxoZWFkPlxuICAgICAgICA8bWV0YSBjaGFyc2V0PVwiVVRGLThcIiAvPlxuICAgICAgICA8bWV0YSBuYW1lPVwidmlld3BvcnRcIiBjb250ZW50PVwid2lkdGg9ZGV2aWNlLXd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19UEsBAhQACgAAAAAAwbVKRTPBdC5wBAAAcAQAAAQAAAAAAAAAAAAAAAAAAAAAAGRhdGFQSwUGAAAAAAEAAQAyAAAAkgQAAAAA)

```js
// hasは、プロパティ名が含まれているかを調べる
console.log(_({"a": 1, "b": 2, "c": 3}).has("a"));
```

```js
console.log(_.has({"a": 1, "b": 2, "c": 3}, "a"));
```

[groupBy](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAABCaSkUX6VLbjgQAAI4EAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7Pjg5fjg6zjg7zjg4jkvZzjgaPjgabjgb/jgb7jgZfjgZ/imaoifSwiY29kZSI6eyJodG1sIjp7InR5cGUiOiJodG1sIiwidmFsdWUiOiI8IURPQ1RZUEUgaHRtbD5cbiBcbjxodG1sPlxuICAgIDxoZWFkPlxuICAgICAgICA8bWV0YSBjaGFyc2V0PVwiVVRGLThcIiAvPlxuICAgICAgICA8bWV0YSBuYW1lPVwidmlld3BvcnRcIiBjb250ZW50PVwid2lkdGg9ZGV2aWNlLXdpZHRoLCB1c2VyLXNjYWxhYmxlPW5vXCIgLz5cbiAgICAgICAgPG1ldGEgbmFtZT1cImFwcGxlLW1vYmlsZS13ZWItYXBwLWNhcGFibGVcIiBjb250ZW50PVwieWVzXCIgLz5cbiBcbiAgICAgICAgPHRpdGxlPiR7dGl0bGV9PC90aXRsZT5cbiAgICAgICAgPG1ldGEgbmFtZT1cImRlc2NyaXB0aW9uXCIgY29udGVudD1cIiR7ZGVzY3JpcHRpb259XCIgLz5cbiAgICAgICAgPHN0eWxlPiR7c3R5bGV9PC9zdHlsZT5cbiAgICAgICAgXG4gICAgICAgIDxzY3JpcHQgc3JjPVwiaHR0cHM6Ly9jZG4ucmF3Z2l0LmNvbS9qYXNoa2VuYXMvdW5kZXJzY29yZS9hZmQ0NzM2YTFiNjRjMTAwN2ZhOTQwZTE5M2U4ODgwZGRlM2VlNzRmL3VuZGVyc2NvcmUuanNcIj48L3NjcmlwdD5cbiAgICAgICAgPHNjcmlwdD4ke3NjcmlwdH08L3NjcmlwdD5cblxuICAgIDwvaGVhZD5cbiAgICA8Ym9keT5cbiAgICA8L2JvZHk+XG48L2h0bWw+In0sInN0eWxlIjp7InR5cGUiOiJjc3MiLCJ2YWx1ZSI6ImJvZHkge1xuICAgIGJhY2tncm91bmQtY29sb3I6IFwiI2VlZVwiO1xufSJ9LCJzY3JpcHQiOnsidHlwZSI6ImphdmFzY3JpcHQiLCJ2YWx1ZSI6Ii8qXG4gKiBVbmRlcnNjb3JlLmpzIOOCteODs+ODl+ODq1xuICovXG5cbi8vIGdyb3VwQnnjga/jgIHnmbvpjLLjgZfjgZ/plqLmlbDjga7ov5TjgorlgKTjgafliIbpoZ7jgZfjgabjgqrjg5bjgrjjgqfjgq/jg4jljJbjgZfjgabjgY/jgozjgotcbmNvbnNvbGUuZGlyKF8oWzEsMywxMiw4LDksMTIsMTIsOV0pLmdyb3VwQnkoZnVuY3Rpb24gKG51bSkge1xuICAgIHJldHVybiBudW0lMjsgLy8g5aWH5pWw44Go5YG25pWw44Gr5YiG6aGeXG59KSk7XG4ifX19UEsBAhQACgAAAAAAEJpKRRfpUtuOBAAAjgQAAAQAAAAAAAAAAAAAAAAAAAAAAGRhdGFQSwUGAAAAAAEAAQAyAAAAsAQAAAAA)

```js
// groupByは、登録した関数の返り値で分類してオブジェクト化してくれる
console.dir(_([1,3,12,8,9,12,12,9]).groupBy(function (num) {
    return num%2; // 奇数と偶数に分類
}));
```

```js
console.dir(_.groupBy([1,3,12,8,9,12,12,9], function (num) {
    return num%2;
}));
```

[countBy](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAAC2bSkVaCU3hkQQAAJEEAAAEAAAAZG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iLCJ2YWx1ZSI6ImJvZHkge1xuICAgIGJhY2tncm91bmQtY29sb3I6IFwiI2VlZVwiO1xufSJ9LCJzY3JpcHQiOnsidHlwZSI6ImphdmFzY3JpcHQiLCJ2YWx1ZSI6Ii8qXG4gKiBVbmRlcnNjb3JlLmpzIOOCteODs+ODl+ODq1xuICovXG5cbi8vIGNvdW50Qnnjga9ncm91cEJ544Go5Ly844Gm44GE44Gm44CB5YiG6aGe44GZ44KLXG4vLyDjgZ/jgaDjgIHpgZXjgYbjga7jga/liIbpoZ7lvozjga7mlbDjgpLov5TjgZlcbmNvbnNvbGUuZGlyKF8oWzEsMywxMiw4LDksMTIsMTIsOV0pLmNvdW50QnkoZnVuY3Rpb24gKG51bSkge1xuICAgIHJldHVybiBudW0lMjsgLy8g5aWH5pWw44Go5YG25pWw44Gr5YiG6aGeXG59KSk7XG4ifX19UEsBAhQACgAAAAAALZtKRVoJTeGRBAAAkQQAAAQAAAAAAAAAAAAAAAAAAAAAAGRhdGFQSwUGAAAAAAEAAQAyAAAAswQAAAAA)

```js
// countByはgroupByと似ていて、分類する
// ただ、違うのは分類後のカウント数を返す
console.dir(_([1,3,12,8,9,12,12,9]).countBy(function (num) {
    return num%2; // 奇数と偶数に分類
}));
```

```js
console.dir(_.countBy([1,3,12,8,9,12,12,9], function (num) {
    return num%2;
}));
```

[sortBy](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAAGWbSkUpP+OHRAQAAEQEAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7Pjg5fjg6zjg7zjg4jkvZzjgaPjgabjgb/jgb7jgZfjgZ/imaoifSwiY29kZSI6eyJodG1sIjp7InR5cGUiOiJodG1sIiwidmFsdWUiOiI8IURPQ1RZUEU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IoXyhbMSwzLDEyLDgsOSwxMiwxMiw5XSkuc29ydEJ5KGZ1bmN0aW9uIChudW0pIHtcbiAgICByZXR1cm4gbnVtO1xufSkpO1xuIn19fVBLAQIUAAoAAAAAAGWbSkUpP+OHRAQAAEQEAAAEAAAAAAAAAAAAAAAAAAAAAABkYXRhUEsFBgAAAAABAAEAMgAAAGYEAAAAAA==)

```js
// sortByは、登録した返り値でソートする
console.dir(_([1,3,12,8,9,12,12,9]).sortBy(function (num) {
    return num;
}));
```

```js
console.dir(_.sortBy([1,3,12,8,9,12,12,9], function (num) {
    return num;
}));
```

[union](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAAKecSkWZ0XrcvQQAAL0EAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7Pjg5fjg6zjg7zjg4jkvZzjgaPjgabjgb/jgb7jgZfjgZ/imaoifSwiY29kZSI6eyJodG1sIjp7InR5cGUiOiJodG1sIiwidmFsdWUiOiI8IURPQ1RZUEUgaHRtbD5cbiBcbjxodG1sPlxuICAgIDxoZWFkPlxuICAgICAgICA8bWV0YSBjaGFyc2V0PVwiVVRGLThcIiAvPlxuICAgICAgICA8bWV0YSBuYW1lPVwidmlld3BvcnRcIiBjb250ZW50PVwid2lkdGg9ZGV2aWNlLXdpZHRoLCB1c2VyLXNjYWxhYmxlPW5vXCIgLz5cbiAgICAgICAgPG1ldGEgbmFtZT1cImFwcGxlLW1vYmlsZS13ZWItYXBwLWNhcGFibGVcIiBjb250ZW50PVwieWVzXCIgLz5cbiBcbiAgICAgICAgPHRpdGxlPiR7dGl0bGV9PC90aXRsZT5cbiAgICAgICAgPG1ldGEgbmFtZT1cImRlc2NyaXB0aW9uXCIgY29udGVudD1cIiR7ZGVzY3JpcHRpb259XCIgLz5cbiAgICAgICAgPHN0eWxlPiR7c3R5bGV9PC9zdHlsZT5cbiAgICAgICAgXG4gICAgICAgIDxzY3JpcHQgc3JjPVwiaHR0cHM6Ly9jZG4ucmF3Z2l0LmNvbS9qYXNoa2VuYXMvdW5kZXJzY29yZS9hZmQ0NzM2YTFiNjRjMTAwN2ZhOTQwZTE5M2U4ODgwZGRlM2VlNzRmL3VuZGVyc2NvcmUuanNcIj48L3NjcmlwdD5cbiAgICAgICAgPHNjcmlwdD4ke3NjcmlwdH08L3NjcmlwdD5cblxuICAgIDwvaGVhZD5cbiAgICA8Ym9keT5cbiAgICA8L2JvZHk+XG48L2h0bWw+In0sInN0eWxlIjp7InR5cGUiOiJjc3MiLCJ2YWx1ZSI6ImJvZHkge1xuICAgIGJhY2tncm91bmQtY29sb3I6IFwiI2VlZVwiO1xufSJ9LCJzY3JpcHQiOnsidHlwZSI6ImphdmFzY3JpcHQiLCJ2YWx1ZSI6Ii8qXG4gKiBVbmRlcnNjb3JlLmpzIOOCteODs+ODl+ODq1xuICovXG5cbi8vIHVuaW9u44Gv44CB44Om44OL44O844Kv44Gq5YCk44Gg44GR44Gn6YWN5YiX44KS5L2c5oiQ44GZ44KLXG5jb25zb2xlLmxvZyhfKFsxLDMsMTIsOCw5LDEyLDEyLDksNF0pLnVuaW9uKCkpO1xuXG4vLyDphY3liJfjgpLntbHlkIjjgZfjgabjgIHjg6bjg4vjg7zjgq/jgarlgKTjga7phY3liJfjgpLkvZzmiJDjgZnjgovjgZPjgajjgoLjgafjgY3jgotcbmNvbnNvbGUubG9nKF8udW5pb24oWzEsMywxMiw4LDksMTIsMTIsOSw0XSwgWzEwLDExLDEyXSkpOyJ9fX1QSwECFAAKAAAAAACnnEpFmdF63L0EAAC9BAAABAAAAAAAAAAAAAAAAAAAAAAAZGF0YVBLBQYAAAAAAQABADIAAADfBAAAAAA=)

```js
// unionは、ユニークな値だけで配列を作成する
console.log(_([1,3,12,8,9,12,12,9,4]).union());
```

```js
console.log(_.union([1,3,12,8,9,12,12,9,4]));
```

[uniq](http://phi-jp.github.io/runstant/release/alpha/index.html#UEsDBAoAAAAAAAK1SkWMnqA+sAQAALAEAAAEAAAAZGF0YXsidmVyc2lvbiI6IjAuMC4xIiwiY3VycmVudCI6InNjcmlwdCIsInNldHRpbmciOnsidGl0bGUiOiJ0ZW1wbGF0ZSAtIEVDTUFTY3JpcHQgNiIsImRldGFpbCI6IkVDTUFTY3JpcHQgNiDjga7jg4bjg7Pjg5fjg6zjg7zjg4jkvZzjgaPjgabjgb/jgb7jgZfjgZ/imaoifSwiY29kZSI6eyJodG1sIjp7InR5cGUiOiJodG1sIiwidmFsdWUiOiI8IURPQ1RZUEUgaHRtbD5cbiBcbjxodG1sPlxuICAgIDxoZWFkPlxuICAgICAgICA8bWV0YSBjaGFyc2V0PVwiVVRGLThcIiAvPlxuICAgICAgICA8bWV0YSBuYW1lPVwidmlld3BvcnRcIiBjb250ZW50PVwid2lkdGg9ZGV2aWNlLXdpZHRoLCB1c2VyLXNjYWxhYmxlPW5vXCIgLz5cbiAgICAgICAgPG1ldGEgbmFtZT1cImFwcGxlLW1vYmlsZS13ZWItYXBwLWNhcGFibGVcIiBjb250ZW50PVwieWVzXCIgLz5cbiBcbiAgICAgICAgPHRpdGxlPiR7dGl0bGV9PC90aXRsZT5cbiAgICAgICAgPG1ldGEgbmFtZT1cImRlc2NyaXB0aW9uXCIgY29udGVudD1cIiR7ZGVzY3JpcHRpb259XCIgLz5cbiAgICAgICAgPHN0eWxlPiR7c3R5bGV9PC9zdHlsZT5cbiAgICAgICAgXG4gICAgICAgIDxzY3JpcHQgc3JjPVwiaHR0cHM6Ly9jZG4ucmF3Z2l0LmNvbS9qYXNoa2VuYXMvdW5kZXJzY29yZS9hZmQ0NzM2YTFiNjRjMTAwN2ZhOTQwZTE5M2U4ODgwZGRlM2VlNzRmL3VuZGVyc2NvcmUuanNcIj48L3NjcmlwdD5cbiAgICAgICAgPHNjcmlwdD4ke3NjcmlwdH08L3NjcmlwdD5cblxuICAgIDwvaGVhZD5cbiAgICA8Ym9keT5cbiAgICA8L2JvZHk+XG48L2h0bWw+In0sInN0eWxlIjp7InR5cGUiOiJjc3MiLCJ2YWx1ZSI6ImJvZHkge1xuICAgIGJhY2tncm91bmQtY29sb3I6IFwiI2VlZVwiO1xufSJ9LCJzY3JpcHQiOnsidHlwZSI6ImphdmFzY3JpcHQiLCJ2YWx1ZSI6Ii8qXG4gKiBVbmRlcnNjb3JlLmpzIOOCteODs+ODl+ODq1xuICovXG5cbi8vIHVuaXHjga/jgIHjg6bjg4vjg7zjgq/jgarlgKTjgaDjgZHjgafphY3liJfjgpLkvZzmiJDjgZnjgotcbi8vIOaXouOBq+OCveODvOODiOa4iOOBv+OBoOOBo+OBn+OCieOAgeW8leaVsOOBq3RydWXjgpLmuKHjgZnjgajjgojjgorpq5jpgJ/jgavli5XkvZzjgZnjgoso44KJ44GX44GEKVxuLy8g44OH44OV44Kp44Or44OI44GvZmFsc2VcbmNvbnNvbGUubG9nKF8oWzEsMywxMiw4LDksMTIsMTIsOSw0XSkudW5pcShmYWxzZSkpO1xuIn19fVBLAQIUAAoAAAAAAAK1SkWMnqA+sAQAALAEAAAEAAAAAAAAAAAAAAAAAAAAAABkYXRhUEsFBgAAAAABAAEAMgAAANIEAAAAAA==)

```js
// uniqは、ユニークな値だけで配列を作成する
// 既にソート済みだったら、引数にtrueを渡すとより高速に動作する(らしい)
// デフォルトはfalse
console.log(_([1,3,12,8,9,12,12,9,4]).uniq(false));
```

```js
console.log(_.uniq([1,3,12,8,9,12,12,9,4], false));
```

# かんそう

ruby的な便利関数を`_()`で書けるようになる感じでしょうか。

...実は上記のほとんど、[tmlib.js](http://phi-jp.github.io/tmlib.js/)でできるんですよ。というステマ。

```js
[1,2,3,4].shuffle().each(function (l) {
    console.log(l);
});
```

という感じで。

templateについては別途まとめながら触ってみようかなぁ。