{"id":356,"date":"2009-07-24T05:00:20","date_gmt":"2009-07-24T12:00:20","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1837"},"modified":"2009-07-24T05:00:20","modified_gmt":"2009-07-24T12:00:20","slug":"summarize-contents-of-array","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=356","title":{"rendered":"Summarize Contents of Array"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar a:Array = &#x5B;true, true, true, false, false, true, true, true, false];\r\n\r\nvar counter:int = 0;\r\nvar prev:Boolean;\r\nvar summary:Array = &#x5B;];\r\nfor (var i:int = 1; i&lt;a.length; i++){\r\n\tprev = a&#x5B;i - 1]\r\n\tcounter++;\r\n\tif (prev != a&#x5B;i]){\r\n\t\tif (prev){\r\n\t\t\tsummary.push(&quot;true: &quot;+ counter);\r\n\t\t}else{\r\n\t\t\tsummary.push(&quot;false: &quot;+ counter);\r\n\t\t}\r\n\t\tcounter = 0;\r\n\t}\r\n}\r\nsummary.push(a&#x5B;i-1].toString()+&quot;: &quot;+ (counter+1));\r\n\r\ntrace(summary);\r\n\r\n\/** outputs:\r\ntrue: 3,false: 2,true: 3,false: 1\r\n*\/\r\n<\/pre>\n<p>This is a handy way to summarize the contents of an array of boolean values. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>var a:Array = &#x5B;true, true, true, false, false, true, true, true, false]; var counter:int = 0; var prev:Boolean; var summary:Array = &#x5B;]; for (var i:int = 1; i&lt;a.length; i++){ prev = a&#x5B;i &#8211; 1] counter++; if (prev != a&#x5B;i]){ if (prev){ summary.push(&quot;true: &quot;+ counter); }else{ summary.push(&quot;false: &quot;+ counter); } counter = 0; } } summary.push(a&#x5B;i-1].toString()+&quot;: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,94],"tags":[3,14,4],"class_list":["post-356","post","type-post","status-publish","format-standard","hentry","category-arrays","category-misc","tag-actionscript","tag-as3","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=356"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}