{"id":8693,"date":"2021-09-05T18:58:27","date_gmt":"2021-09-05T15:58:27","guid":{"rendered":"https:\/\/elzero.org\/?p=8693"},"modified":"2022-08-07T07:07:18","modified_gmt":"2022-08-07T04:07:18","slug":"javascript-problems-solving-number-to-reversed-array","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/javascript-problems-solving-number-to-reversed-array\/","title":{"rendered":"Number To Reversed Array"},"content":{"rendered":"<h3>\u0627\u0644\u062d\u0644 01<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\nfunction convert(n) {\r\n  \/\/ Convert To String\r\n  let arr = n.toString();\r\n  \/\/ Convert To Array\r\n  arr = arr.split(\"\");\r\n  \/\/ Convert Every Element To Number\r\n  arr = arr.map((x) => parseInt(x));\r\n  \/\/ Reverse Array Elements\r\n  arr = arr.reverse();\r\n  return arr;\r\n}\r\n\r\nconsole.log(convert(564987654)); \/\/ [4, 5, 6, 7, 8, 9, 4, 6, 5]\r\nconsole.log(convert(529132)); \/\/ [2, 3, 1, 9, 2, 5]\r\n<\/script>\r\n\r\n<hr class=\"separator\">\r\n\r\n<h3>\u0627\u0644\u062d\u0644 01 \u0628\u0633\u0637\u0631 \u0648\u0627\u062d\u062f \u0641\u0642\u0637<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\nfunction convert(n) {\r\n  return n.toString().split(\"\").map((x) => parseInt(x)).reverse();\r\n}\r\n\r\nconsole.log(convert(564987654)); \/\/ [4, 5, 6, 7, 8, 9, 4, 6, 5]\r\nconsole.log(convert(529132)); \/\/ [2, 3, 1, 9, 2, 5]\r\n<\/script>\r\n\r\n<hr class=\"separator\">\r\n\r\n<h3>\u0627\u0644\u062d\u0644 02<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\nfunction convert(n) {\r\n  \/\/ Convert To String\r\n  let arrayOfChars = n.toString();\r\n\r\n  \/\/ Create Empty Array\r\n  let emptyArray = [];\r\n\r\n  \/\/ Loop On String\r\n  for (let i = 0; i < arrayOfChars.length; i++) {\r\n    emptyArray.push(+arrayOfChars[i]);\r\n  }\r\n\r\n  \/\/ Reverse Array Order\r\n  let result = emptyArray.reverse();\r\n\r\n  return result;\r\n}\r\n\r\nconsole.log(convert(564987654)); \/\/ [4, 5, 6, 7, 8, 9, 4, 6, 5]\r\nconsole.log(convert(529132)); \/\/ [2, 3, 1, 9, 2, 5]\r\n<\/script>\r\n\r\n<hr class=\"separator\">\r\n\r\n<h3>\u0627\u0644\u062d\u0644 03<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\nfunction convert(n) {\r\n  \/\/ Convert To String\r\n  let arrayOfChars = n.toString();\r\n\r\n  \/\/ Create Empty Array\r\n  let emptyArray = [];\r\n\r\n  \/\/ Loop On String\r\n  for (let i = 0; i < arrayOfChars.length; i++) {\r\n    \/\/ Use Unshift To Add Element In The Start\r\n    emptyArray.unshift(+arrayOfChars[i]);\r\n  }\r\n\r\n  return emptyArray;\r\n}\r\n\r\nconsole.log(convert(564987654)); \/\/ [4, 5, 6, 7, 8, 9, 4, 6, 5]\r\nconsole.log(convert(529132)); \/\/ [2, 3, 1, 9, 2, 5]\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0627\u0644\u062d\u0644 01 \u0627\u0644\u062d\u0644 01 \u0628\u0633\u0637\u0631 \u0648\u0627\u062d\u062f \u0641\u0642\u0637 \u0627\u0644\u062d\u0644 02 \u0627\u0644\u062d\u0644 03<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1337],"tags":[],"class_list":["post-8693","post","type-post","status-publish","format-standard","hentry","category-problems-solving"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/8693","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=8693"}],"version-history":[{"count":2,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/8693\/revisions"}],"predecessor-version":[{"id":8696,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/8693\/revisions\/8696"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=8693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=8693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=8693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}