{"id":8093,"date":"2019-12-06T11:00:39","date_gmt":"2019-12-06T02:00:39","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=8093"},"modified":"2019-12-06T11:50:56","modified_gmt":"2019-12-06T02:50:56","slug":"lodash-js-array-object-part-3-final","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/8093","title":{"rendered":"Lodash Js Array &amp; Object &#8211; Part 3 (Final)"},"content":{"rendered":"\n<p>Today I will talk about dealing with array and object in Lodash Js.<\/p>\n\n\n\n<h3>Filter<\/h3>\n\n\n\n<ul><li>Filtering a list to transform the elements we want to get back<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>var numbers = _.range(0,10);      \/\/ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n\nvar evenNumbers = _.filter(numbers, function(e){ return e % 2 != 0; });\n\/\/ evenNumbers is now [ 0, 2, 4, 6, 8 ]\n<\/code><\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/HlaingTinHtun\/Lodash_Js_Research_Development\/blob\/master\/basic_workflows\/lists%26arrays.md#reduce\"><\/a>Reduce<\/h3>\n\n\n\n<ul><li>Reducing a list of objects to a single value.<\/li><li>Ex=&gt;A group of people can buy a meal or not. In that case we have to check out they have the enough amount by the sum of money they have.<\/li><li>(Each&#8217;s money =&gt; sum money)<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>var ppl = [\n    {\n        'name': 'Keita',\n        'money': 1000\n    },\n    {\n        'name': 'Sato',\n        'money': 3000\n    },\n    {\n        'name': 'Ruma',\n        'money': 500\n    },\n]\n\nvar sumMoney = function(data){\n    return _.reduce(\n        data,\n        function(accumulated, e){\n            return accumulated + e.money;\n        },\n        0\n    );\n}\n\nfunction canBuyMeal(data){\n    return 3500 &lt; sumMoney(data);\n}\n\ncanBuyMeal(ppl);    \/\/ returns true\n<\/code><\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/HlaingTinHtun\/Lodash_Js_Research_Development\/blob\/master\/basic_workflows\/lists%26arrays.md#some\"><\/a>Some<\/h3>\n\n\n\n<ul><li>If there is at least one record in a collection that meets some criteria.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>var ppl = [\n    {\n        'name': 'Keita',\n        'hasMoney': true\n    },\n    {\n        'name': 'Sato',\n        'hasMoney': false\n    },\n    {\n        'name': 'Ruma',\n        'hasProperty': true\n    },\n]\n\nfunction canLive(data){\n    return _.some(data, function(e){ return e.hasProperty; });\n}\n\ncanGroupDrive(ppl);    \/\/ returns true\n<\/code><\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/HlaingTinHtun\/Lodash_Js_Research_Development\/blob\/master\/basic_workflows\/lists%26arrays.md#map\"><\/a>Map<\/h3>\n\n\n\n<ul><li>Useful for changing a list into a different list in a purely declarative way.<\/li><li>Can just specify how you want to manipulate an element of a list.<\/li><li>Make a new list transformed by providing a function<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>var res1 = _.range(5);       \/\/ [ 0, 1, 2, 3, 4]\n\nvar res2 = _.map(a, function(e){ return e + e;} );\n\n\/\/result is [0, 2, 4, 6, 8]<\/code><\/pre>\n\n\n\n<p>By Yuuma<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8093\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/8093\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"Lodash Js Array &amp; Object &#8211; Part 3 (Final)\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8093\" data-text=\"Lodash Js Array &amp; Object &#8211; Part 3 (Final)\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8093\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8093\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Today I will talk about dealing with array and object in Lodash Js. Filter Filtering a list to transform the e [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8093"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=8093"}],"version-history":[{"count":3,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8093\/revisions"}],"predecessor-version":[{"id":8098,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8093\/revisions\/8098"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=8093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=8093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=8093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}