{"id":736,"date":"2014-09-18T22:28:58","date_gmt":"2014-09-18T22:28:58","guid":{"rendered":"http:\/\/blog.silverterra.net\/?p=736"},"modified":"2015-02-07T01:29:32","modified_gmt":"2015-02-07T01:29:32","slug":"javascript-array-rotate","status":"publish","type":"post","link":"https:\/\/blog.silverterra.net\/?p=736","title":{"rendered":"javascript array rotate"},"content":{"rendered":"<blockquote><p>Goal: to rotate a javascript array<\/p><\/blockquote>\n<p>This is similar to the assembly shift operation with bites 01011 -> rotate left 2 -> 01101<\/p>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\n  var array = [0,1,0,1,1];\r\n  \/\/ 0,1,1,0,1\r\n<\/pre>\n<p>The solution is simple:<\/p>\n<p><code data-enlighter-language=\"js\" class=\"EnlighterJSRAW\"><\/code><br \/>\nfor (var i = 0; i < 2; i++) {\n  array.push(array.shift());\n}\n[\/js]\n\n\n<ul>\n<li>The shift() will cut\/remove the first element from the array.<\/li>\n<li>The second step is to put\/paste this element to the end of the array (push).<\/li>\n<li>Repeat the steps with a cycle<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Goal: to rotate a javascript array This is similar to the assembly shift operation with bites 01011 -> rotate left 2 -> 01101 The solution is simple: for (var i = 0; i < 2; i++) { array.push(array.shift()); } [\/js] The shift() will cut\/remove the first element from the array. The second step is to [&hellip;]\n<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-736","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=736"}],"version-history":[{"count":1,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/736\/revisions"}],"predecessor-version":[{"id":737,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/736\/revisions\/737"}],"wp:attachment":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}