{"id":105808,"date":"2017-04-28T12:59:07","date_gmt":"2017-04-28T03:59:07","guid":{"rendered":"http:\/\/www.key-p.com\/blog\/staff\/?p=105808"},"modified":"2017-09-01T18:45:49","modified_gmt":"2017-09-01T09:45:49","slug":"lodash%e3%81%ae_-chunk%e9%96%a2%e6%95%b0%e3%81%a8_-partition%e9%96%a2%e6%95%b0%e3%81%ae%e7%b4%b9%e4%bb%8b","status":"publish","type":"post","link":"https:\/\/www.key-p.com\/blog\/staff\/archives\/105808","title":{"rendered":"Lodash\u306e_.chunk\u95a2\u6570\u3068_.partition\u95a2\u6570\u306e\u7d39\u4ecb"},"content":{"rendered":"<p>\n<a href=\"http:\/\/www.key-p.com\/blog\/staff\/wp-content\/uploads\/2017\/04\/20170427blog.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-105858\" src=\"http:\/\/www.key-p.com\/blog\/staff\/wp-content\/uploads\/2017\/04\/20170427blog.png\" alt=\"20170427blog\" width=\"466\" height=\"298\" \/><\/a><br \/>\nt\u3067\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u3001JavaScript\u306e\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3042\u308b\u3001<a href=\"https:\/\/lodash.com\/\" target=\"_blank\">Lodash<\/a>\u306b\u3064\u3044\u3066\u66f8\u304d\u307e\u3059\u3002<br \/>\n<br \/>\n\u6700\u8fd1\u3067\u306f\u3001Lodash\u306e\u6a5f\u80fd\u3082\u3001JavaScript\u306b\u6a19\u6e96\u3067\u7528\u610f\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<br \/>\n\u4f8b\u3048\u3070\u3001Lodash\u306e_.keys\u95a2\u6570\u3084_.some\u95a2\u6570\u306f\u3001JavaScript\u306b\u6a19\u6e96\u3067\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n<br \/>\n<a href=\"https:\/\/lodash.com\/docs\/#some\" target=\"_blank\">_.some\u95a2\u6570<\/a><a href=\"https:\/\/developer.mozilla.org\/ja\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Array\/some\" target=\"new\">Array.prototype.some()<\/a><br \/>\n<table>\n<tbody>\n<tr>\n<th style=\"width: 200px; border: solid thin #595959; padding: 5px; text-align: center; font-weight: bold; background-color: #99ccff;\">Lodash<\/th>\n<th style=\"width: 200px; border: solid thin #595959; padding: 5px; text-align: center; font-weight: bold; bold;background-color: #99CCFF;\">JavaScript\u6a19\u6e96<\/th>\n<\/tr>\n<tr>\n<td style=\"border: solid 1px #595959; margin: 5px; padding: 5px;\"><a href=\"https:\/\/lodash.com\/docs\/#keys\" target=\"_blank\">_.keys\u95a2\u6570<\/a><\/td>\n<td style=\"border: solid 1px #595959; margin: 5px; padding: 5px;\"><a href=\"https:\/\/developer.mozilla.org\/ja\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Object\/keys\" target=\"new\">Object.keys()<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\u3057\u304b\u3057\u3001Lodash\u306b\u3057\u304b\u306a\u3044\u95a2\u6570\u3082\u591a\u304f\u3042\u308a\u307e\u3059\u3002\u4eca\u56de\u306f\u3001\u4f7f\u3063\u3066\u307f\u3066\u4fbf\u5229\u3060\u3063\u305f2\u3064\u306e\u95a2\u6570\u3092\u3001\u4f8b\u3092\u4ea4\u3048\u306a\u304c\u3089\u7d39\u4ecb\u3057\u307e\u3059\u3002<br \/>\n<h3>\u5b9f\u884c\u74b0\u5883<\/h3>\n\u4f8b\u306b\u6319\u3052\u308b\u30b3\u30fc\u30c9\u306f\u3001\u4ee5\u4e0b\u306e\u74b0\u5883\u3067\u52d5\u4f5c\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n<ul>\n \t<li>Node v7.9.0<\/li>\n \t<li>Lodash v4.17.4<\/li>\n<\/ul>\n<h3>_.chunk\u95a2\u6570<\/h3>\n<a href=\"https:\/\/lodash.com\/docs\/#chunk\" target=\"_blank\">_.chunk\u95a2\u6570<\/a>\u306f\u3001\u914d\u5217\u306e\u8981\u7d20\u3092\u4e00\u5b9a\u306e\u8981\u7d20\u6570\u3054\u3068\u306b\u5206\u3051\u308b\u95a2\u6570\u3067\u3059\u3002<br \/>\n\u5927\u91cf\u306e\u8981\u7d20\u3092\u5c11\u3057\u305a\u3064\u51e6\u7406\u3057\u305f\u3044\u5834\u5408\u306b\u3001\u4e00\u5b9a\u6570\u3054\u3068\u306b\u5206\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u4fbf\u5229\u3067\u3059\u3002<br \/>\n<h4>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/h4>\n3\u8981\u7d20\u3054\u3068\u306b\u5206\u3051\u3089\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3059\u3002<br \/>\n<pre class=\"toolbar:1 lang:js decode:true\" title=\"chunk-basic.js\">const _ = require( 'lodash' );\n\n\/\/ \u30c7\u30fc\u30bf\nconst array = [ 1, 2, 3, 4, 5, 6, 7, 8 ];\n\n\/\/ _.chunk\u95a2\u6570\u3067\u3001\u914d\u5217\u306e\u8981\u7d20\u30923\u3064\u305a\u3064\u306b\u5206\u3051\u308b\nconsole.log( _.chunk( array, 3 ) );\n\n\/\/ \u7d50\u679c: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]\n\n<\/pre>\n<h4>\u30e6\u30fc\u30b6\u30c7\u30fc\u30bf\u3092100\u4ef6\u305a\u3064\u30b5\u30fc\u30d0\u306b\u9001\u4fe1\u3059\u308b\u5834\u5408<\/h4>\n\u5927\u91cf\u306e\u30e6\u30fc\u30b6\u30c7\u30fc\u30bf\u304c\u3042\u308a\u3001\u305d\u308c\u3092\u5206\u5272\u3057\u3066\u30b5\u30fc\u30d0\u306b\u9001\u4fe1\u3059\u308b\u4f8b\u3092\u6319\u3052\u3066\u3044\u307e\u3059\u3002<br \/>\n1\u4e07\u4ef6\u306a\u3069\u5927\u91cf\u306e\u30c7\u30fc\u30bf\u3092\u9001\u4fe1\u3059\u308b\u6642\u3001\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306b\u8ca0\u8377\u3092\u4e0e\u3048\u306a\u3044\u3088\u3046\u306b\u3001\u4f55\u4ef6\u304b\u533a\u5207\u308a\u3067\u30c7\u30fc\u30bf\u3092\u9001\u4fe1\u3059\u308b\u3053\u3068\u304c\u3042\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002\u305d\u3046\u3044\u3046\u6642\u306b\u3001\u7c21\u5358\u306b\u5206\u5272\u3067\u304d\u308b\u306e\u3067\u4fbf\u5229\u3067\u3059\u3002<br \/>\n<br \/>\n\u30b5\u30fc\u30d0\u306b\u9001\u4fe1\u3059\u308b\u5834\u5408\u306f\u3001<a href=\"https:\/\/developer.mozilla.org\/ja\/docs\/Web\/API\/Fetch_API\" target=\"_blank\">Fetch API<\/a>\u306a\u3069\u3001Promise\u3092\u8fd4\u3059\u975e\u540c\u671f\u95a2\u6570\u304c\u5229\u7528\u3055\u308c\u308b\u3053\u3068\u304c\u591a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u306a\u306e\u3067\u305d\u308c\u3092\u60f3\u5b9a\u3057\u3001async function\u3068for...of\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u3001sendData\u95a2\u6570\u3092\u9010\u6b21\u5b9f\u884c\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n<pre class=\"toolbar:1 lang:js decode:true\" title=\"chunk-example.js\">const _ = require( 'lodash' );\n\n\/\/ \u5927\u91cf\u306e\u30c7\u30fc\u30bf (1\u4e07\u4ef6\u307b\u3069)\nconst users = [\n  { id: 1, name: 'Alice'   },\n  { id: 2, name: 'Bob'     },\n  { id: 3, name: 'Charlie' },\n  \/* \u7d9a\u304f\u30fb\u30fb\u30fb *\/\n];\n\n\/\/ \u30b5\u30fc\u30d0\u306b\u975e\u540c\u671f\u3067\u30c7\u30fc\u30bf\u3092\u9001\u4fe1\u3057\u3066\u3001Promise\u3092\u8fd4\u3059\nfunction sendData( chunk ) {\n  \/\/ \u9001\u4fe1\u51e6\u7406\n  return Promise.resolve( true );\n}\n\n\/\/ sendData\u95a2\u6570\u3092\u9010\u6b21\u5b9f\u884c\u3059\u308b\nasync function execute() {\n\n  \/\/ _.chunk\u95a2\u6570\u3067\u3001\u914d\u5217\u306e\u8981\u7d20\u3092100\u305a\u3064\u5206\u3051\u308b\n  for ( const chunk of _.chunk( users, 100 ) ) {\n\n    \/\/ 100\u305a\u3064\u306e\u914d\u5217\u3092sendData\u95a2\u6570\u306b\u6e21\u3059\n    await sendData( chunk );\n  }\n}\n\nexecute();\n\n<\/pre>\n<h3>_.partition\u95a2\u6570<\/h3>\n<a href=\"https:\/\/lodash.com\/docs\/#partition\" target=\"_blank\">_.partition\u95a2\u6570<\/a>\u306f\u3001\u6761\u4ef6\u306b\u3088\u3063\u3066\u3001\u914d\u5217\u30922\u3064\u306e\u30b0\u30eb\u30fc\u30d7\u306b\u5206\u3051\u308b\u95a2\u6570\u3067\u3059\u3002<br \/>\n<a href=\"http:\/\/www.key-p.com\/blog\/staff\/archives\/105255\">Lodash\u306eCollection\u306e\u30b7\u30e7\u30fc\u30c8\u30cf\u30f3\u30c9\u306b\u3064\u3044\u3066<\/a>\u3067\u7d39\u4ecb\u3057\u305f\u3001\u30b7\u30e7\u30fc\u30c8\u30cf\u30f3\u30c9\u304c\u5229\u7528\u3067\u304d\u308b\u95a2\u6570\u3067\u3059\u3002<br \/>\n<h4>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/h4>\n\u5e74\u9f62\u306b\u3088\u3063\u30662\u3064\u306e\u30b0\u30eb\u30fc\u30d7\u306b\u5206\u3051\u3066\u3044\u307e\u3059\u3002<br \/>\n\u623b\u308a\u5024\u306f\u30012\u3064\u306e\u914d\u5217\u3067\u69cb\u6210\u3055\u308c\u308b\u914d\u5217\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u524d\u306e\u914d\u5217\u306btrue\u3092\u8fd4\u3057\u305f\u8981\u7d20\u3001\u5f8c\u306e\u914d\u5217\u306bfalse\u3092\u8fd4\u3057\u305f\u8981\u7d20\u304c\u542b\u307e\u308c\u307e\u3059\u3002<br \/>\n<pre class=\"toolbar:1 lang:js decode:true\" title=\"partition-basic.js\">const _ = require( 'lodash' );\n\n\/\/ \u540d\u524d\u3068\u5e74\u9f62\u306e\u914d\u5217\u30c7\u30fc\u30bf\nconst users = [\n  { id: 1, name: 'Alice',   age: 20 },\n  { id: 2, name: 'Bob',     age: 15 },\n  { id: 3, name: 'Charlie', age: 10 },\n];\n\n\/\/ \u5e74\u9f62\u306b\u3088\u3063\u3066\u30012\u3064\u306e\u30b0\u30eb\u30fc\u30d7\u306b\u5206\u3051\u308b\nconsole.log( _.partition( users, user =&gt; user.age &lt; 20 ) );\n\n\/*\n\u7d50\u679c:\n[\n  [\n    { id: 2, name: 'Bob', age: 15 },\n    { id: 3, name: 'Charlie', age: 10 }\n  ],\n  [\n    { id: 1, name: 'Alice', age: 20 }\n  ]\n]\n*\/\n\n<\/pre>\n<h4>_.partition\u95a2\u6570\u3092\u4f7f\u3063\u305f\u307b\u3046\u304c\u826f\u3044\u5834\u5408<\/h4>\n_.filter\u95a2\u6570\u3068_.reject\u95a2\u6570\u3092\u4f7f\u3063\u3066\u3044\u308b\u5834\u9762\u3067\u3001_.partition\u95a2\u6570\u306b\u7f6e\u304d\u63db\u3048\u3089\u308c\u308b\u5834\u5408\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<br \/>\n<br \/>\n\u5148\u306b_.filter\u95a2\u6570\u3067\u62bd\u51fa\u3057\u3066\u3044\u308b\u7b87\u6240\u306b\u3001\u5f8c\u304b\u3089\u624b\u3092\u52a0\u3048\u3066\u3001_.filter\u95a2\u6570\u3067\u62bd\u51fa\u3057\u305f\u9006\u306e\u6761\u4ef6\u306e\u8981\u7d20\u3082\u4f7f\u3044\u305f\u3044\u5834\u5408\u3001_.reject\u95a2\u6570\u3092\u4f7f\u3044\u304c\u3061\u3067\u3059\u3002<br \/>\n\u3057\u304b\u3057\u3001_.filter\u3068_.reject\u3092\u540c\u3058\u6761\u4ef6\u3067\u5b9f\u884c\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001_.partition\u95a2\u6570\u3092\u4f7f\u3048\u3070\u3001\u4e00\u5ea6\u306e\u51e6\u7406\u3067\u30012\u3064\u306e\u30b0\u30eb\u30fc\u30d7\u3092\u62bd\u51fa\u3067\u304d\u307e\u3059\u3002<br \/>\n<pre class=\"toolbar:1 lang:js decode:true\" title=\"partition-example.js\">const _ = require( 'lodash' );\n\n\/\/ \u540d\u524d\u3068\u5e74\u9f62\u306e\u914d\u5217\u30c7\u30fc\u30bf\nconst users = [\n  { id: 1, name: 'Alice',   age: 20 },\n  { id: 2, name: 'Bob',     age: 15 },\n  { id: 3, name: 'Charlie', age: 10 },\n];\n\nlet young, old;\n\n\/\/ _.filter\u95a2\u6570\u3068_.reject\u95a2\u6570\u3092\u4f7f\u3046\u5834\u5408\u3001\u53ef\u80fd\u3060\u304c\u30012\u5ea6\u540c\u3058\u3088\u3046\u306a\u51e6\u7406\u3092\u3059\u308b\u3053\u3068\u306b\u306a\u308b\nyoung = _.filter( users, user =&gt; user.age &lt; 20 );\nold   = _.reject( users, user =&gt; user.age &lt; 20 );\nconsole.log( young, old );\n\n\/\/ _.partition\u95a2\u6570\u306e\u5834\u5408\u3001\u4e00\u5ea6\u306e\u51e6\u7406\u3067\u53d6\u5f97\u3067\u304d\u308b\n[ young, old ] = _.partition( users, user =&gt; user.age &lt; 20 );\nconsole.log( young, old );\n\n\/*\n\u7d50\u679c(\u3069\u3061\u3089\u306e\u5834\u5408\u3082\u4e00\u7dd2):\nyoung = [\n  { id: 2, name: 'Bob', age: 15 },\n  { id: 3, name: 'Charlie', age: 10 }\n]\n\nold = [\n  { id: 1, name: 'Alice', age: 20 }\n]\n*\/\n\n<\/pre>\n<h3>\u6700\u5f8c\u306b<\/h3>\n<a href=\"http:\/\/www.key-p.com\/blog\/staff\/archives\/105255\">Lodash\u306eCollection\u306e\u30b7\u30e7\u30fc\u30c8\u30cf\u30f3\u30c9\u306b\u3064\u3044\u3066<\/a>\u306b\u5f15\u304d\u7d9a\u304d\u3001Lodash\u306e\u7d39\u4ecb\u3067\u3057\u305f\u3002<br \/>\nLodash\u306b\u306f\u3001\u3068\u3066\u3082\u591a\u304f\u306e\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30e1\u30bd\u30c3\u30c9\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n\u77e5\u3063\u3066\u3044\u308b\u3068\u4fbf\u5229\u306b\u4f7f\u3048\u308b\u306e\u3067\u3001\u4e00\u5ea6<a href=\"https:\/\/lodash.com\/docs\/\" target=\"_blank\">Lodash Documents<\/a>\u306b\u76ee\u3092\u901a\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n<br \/>\n<a href=\"http:\/\/www.key-p.com\/recruit\/\" target=\"new\">\u30ad\u30fc\u30fb\u30dd\u30a4\u30f3\u30c8\u3067\u306f\u3001\u3044\u308d\u3044\u308d\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3044\u3053\u306a\u3059\u30a8\u30f3\u30b8\u30cb\u30a2\u3092\u52df\u96c6\u3057\u3066\u3044\u307e\u3059\u3002<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>t\u3067\u3059\u3002 \u4eca\u56de\u306f\u3001JavaScript\u306e\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3042\u308b\u3001Loda &hellip; <a href=\"https:\/\/www.key-p.com\/blog\/staff\/archives\/105808\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":40,"featured_media":105858,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/posts\/105808"}],"collection":[{"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/comments?post=105808"}],"version-history":[{"count":46,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/posts\/105808\/revisions"}],"predecessor-version":[{"id":106241,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/posts\/105808\/revisions\/106241"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/media\/105858"}],"wp:attachment":[{"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/media?parent=105808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/categories?post=105808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/tags?post=105808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}