{"id":741,"date":"2024-11-25T14:23:30","date_gmt":"2024-11-25T14:23:30","guid":{"rendered":"http:\/\/monkey.ploogie.co.uk\/?page_id=741"},"modified":"2024-12-16T14:59:22","modified_gmt":"2024-12-16T14:59:22","slug":"mwnci-sort-function-2","status":"publish","type":"page","link":"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-sort-function-2\/","title":{"rendered":"Mwnci sort() Function"},"content":{"rendered":"<h2>Syntax<\/h2>\n<p>sort<strong>(<em>array<\/em>)<\/strong><br \/>\nrsort<strong>(<em>array<\/em>)<\/strong><\/p>\n<h2>Description<\/h2>\n<p>The <i>sort()<\/i> function returns a new array sorted in ascending order.<br \/>\nThe <i>rsort()<\/i> function returns a new array sorted in descending order.<\/p>\n<h2>Example<\/h2>\n<pre>\r\na=[5,4,3,2,1]\r\nb=sort(a)\r\nprintln(a,\"\\n\", b)\r\n\r\n\r\n[5, 4, 3, 2, 1]\r\n[1, 2, 3, 4, 5]\r\n<\/pre>\n<p><i>sort()<\/i> is unable to manage mixed data with much intelligence, so results will often cause confusion, anger, and has sometimes been known to induce alcohol consumption.<\/p>\n<h2>Further Examples<\/h2>\n<pre>\r\na=[2.1, 4, 3, 1.1, 1]\r\nb=[1.2, 2.2, 3, 1]\r\nc=[1, 2.1, 3, 4.2, \"norbert\"]\r\nprintln(\"a=\", sort(a))\r\nprintln(\"b=\", sort(b))\r\nprintln(\"c=\", sort(c))\r\nprintln(\"a=\", rsort(a))\r\nprintln(\"b=\", rsort(b))\r\nprintln(\"c=\", rsort(c))\r\n\r\n\r\n\r\na=[1, 1.1, 3, 4, 2.1]\r\nb=[1, 3, 1.2, 2.2]\r\nc=[2.1, 4.2, 1, 3, \"norbert\"]\r\na=[2.1, 4, 3, 1.1, 1]\r\nb=[2.2, 1.2, 3, 1]\r\nc=[\"norbert\", 3, 1, 4.2, 2.1]\r\n\r\n<\/pre>\n<p>If you need to sort a mixture of integers and floating point numbers, then<br \/>\nyou may want to do:<\/p>\n<pre>\r\na=[1, 1.1, 3, 4, 2.1]\r\nprintln(sort(float(a)))\r\nprintln(rsort(float(a)))\r\n\r\n\r\n[1, 1.1, 2.1, 3, 4]\r\n[4, 3, 2.1, 1.1, 1]\r\n<\/pre>\n<p>Which will covert the contents of the array to floating point numbers prior to a sort.<\/p>\n<p>This function is still in flux and if enough alcohol is consumed, I may fix the integer\/float thingy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Syntax sort(array) rsort(array) Description The sort() function returns a new array sorted in ascending order. The rsort() function returns a new array sorted in descending order. Example a=[5,4,3,2,1] b=sort(a) println(a,&#8221;\\n&#8221;, b) [5, 4, 3, 2, 1] [1, 2, 3, 4, 5] sort() is unable to manage mixed data with much intelligence, so results will often &hellip; <a href=\"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-sort-function-2\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Mwnci sort() Function&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-741","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=741"}],"version-history":[{"count":3,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/741\/revisions"}],"predecessor-version":[{"id":1007,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/741\/revisions\/1007"}],"wp:attachment":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}