{"id":19017,"date":"2020-07-06T14:16:40","date_gmt":"2020-07-06T21:16:40","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=19017"},"modified":"2020-12-29T13:41:15","modified_gmt":"2020-12-29T21:41:15","slug":"javascript-reverse-string","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/","title":{"rendered":"JavaScript Reverse String Code Challenge"},"content":{"rendered":"\n<p>One of the first code\/algorithm challenges that we set out to solve as budding software engineers and web developers is to see if we can figure out how to reverse a string. Remember that a string is just a collection of characters and spaces. What we need to set out to do is to try to reverse, for example, the string \u201cHello World!\u201d and return \u201c!dlroW olleH\u201d. There are several ways we can solve this problem and we\u2019ll cover a few of them here in this article.&nbsp;<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Prompt<\/h3>\n\n\n\n<p>Write a function, <code>reverseString<\/code>,&nbsp; that reverses a string and returns it. The string to reverse is given as an argument in the function.&nbsp;<br><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Solution # 1: For Loop<\/h4>\n\n\n\n<p>The first, and probably one of the most straightforward solutions is to use a for loop and go backwards through the string. We\u2019ll need to instantiate, or create, a variable that holds the new reversed string as we pass each character in the string: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>function reverseString(str) {\n               let newStr = '';\n               for(let i = str.length - 1; i &gt;= 0; i--) {\n                   newStr += str[i];\n               }\n               return newStr;\n           }<\/pre><\/div>\n\n\n\n<p>We assign<em> i <\/em>to the last index (which is figured out when we take 1 from the length of the string) \u21d2 this is our <strong>initialization<\/strong> and will serve as the first index we loop through. The second portion of the for loop is our <strong><em>condition <\/em><\/strong><em>\u21d2 <\/em>this tells the loop when to stop. The third and last portion of the for loop is how much our i will <strong><em>increment <\/em><\/strong>after completion of the loop and the condition still holds true :&nbsp; i&#8211; essentially takes our i and reassigns it to i &#8211; 1;<br><\/p>\n\n\n\n<p>As we loop through each iteration we take each character at str[i] and add it to the newStr. We then return the newStr outside of our for loop and terminate the function.&nbsp;<br><\/p>\n\n\n\n<p>Try it yourself in the code editor:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n   &lt;head&gt;\n       &lt;meta charset=&quot;utf-8&quot; \/&gt;\n       &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot; \/&gt;\n       &lt;title&gt;&lt;\/title&gt;\n       &lt;meta name=&quot;description&quot; content=&quot;&quot; \/&gt;\n       &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot; \/&gt;\n       &lt;link rel=&quot;stylesheet&quot; href=&quot;&quot; \/&gt;\n       &lt;script&gt;\n           function reverseString(str) {\n               let newStr = '';\n               for(let i = str.length - 1; i &gt;= 0; i--) {\n                   newStr += str[i];\n               }\n               return newStr;\n           }\n           function showInput(e) {\n               e.preventDefault();\n               const inputStr = document.getElementById('user_input').value;\n               if(inputStr.length &lt; 1) {\n                   alert(&quot;Must enter a string to reverse. Try again.&quot;)\n               }\n               let reversed = reverseString(inputStr);\n \n               document.getElementById(\n                   'display'\n               ).innerHTML = reversed;\n               document.getElementById('user_input').value = '';\n           }\n       &lt;\/script&gt;\n       &lt;style&gt;\n           * {\n               box-sizing: border-box;;\n           }\n           body {\n               width: 100%;\n               max-width: 500px;\n               height: 100vh;\n               background: lightblue;\n               margin: 0 auto;\n               display: flex;\n               flex-flow: column wrap;\n               align-items: center;\n               justify-content: center;\n           }\n           div {\n               display: flex;\n               flex-flow: column wrap;\n               align-items: flex-start;\n               width: 100%;\n           }\n           form {\n               display: flex;\n               flex-flow: column wrap;\n               width: 100%;\n               background: lightgray;\n               padding: 20px;\n               border: 5px double slategray;\n \n \n           }\n           #user_input {\n               width: 100%;\n           }\n           #submit_button {\n               width: 25%;\n               align-self: flex-end;\n               margin-top: 10px;\n           }\n           #display {\n               font-size: 1.4rem;\n               height: 50px;\n           }\n       &lt;\/style&gt;\n   &lt;\/head&gt;\n   &lt;body&gt;\n       &lt;div&gt;\n           &lt;form onsubmit=&quot;showInput(event);&quot;&gt;\n               &lt;label id=&quot;label&quot;&gt;Enter a String to Reverse:&lt;\/label&gt;\n               &lt;input type=&quot;text&quot; name=&quot;message&quot; id=&quot;user_input&quot;\/&gt;\n               &lt;input type=&quot;submit&quot; onclick=&quot;showInput(event);&quot; id=&quot;submit_button&quot;\/&gt;&lt;br \/&gt;\n               &lt;label&gt;Your input: &lt;\/label&gt;\n               &lt;p&gt;&lt;span id=&quot;display&quot;&gt;&lt;\/span&gt;&lt;\/p&gt;\n           &lt;\/form&gt;\n          \n          \n       &lt;\/div&gt;\n   &lt;\/body&gt;\n&lt;\/html&gt;<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Solution # 2: JavaScript\u2019s ES6 map method<\/h4>\n\n\n\n<p>JavaScript has a built in array method that was new to ES6 called <strong>map<\/strong>. What this does is it returns a new array with the specified values. The map method has three parameters: The current item, the index of the item, and a copy of the array it\u2019s coming from. We will use the last two parameters in the solution.&nbsp;<br><\/p>\n\n\n\n<p>The first thing we need to do is split the string into an array using the <code>split()<\/code> method. If we split on an empty string, the method will give us an array with each individual character in it. We then use that new array to map over.&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>function reverseString(str) {\n               let newArr = str.split('');\n               let rev = newArr.map((letter, index, array) =&gt; {\n                   let swapIndex = array.length - index - 1;\n                   return array[swapIndex];\n               });\n               return rev.join('')\n           }<\/pre><\/div>\n\n\n\n<p>Since we are wanting to essentially swap indexes, we need to figure out the index of the character we want to put in the current index\u2019s place. That will be the character we return.&nbsp;<br><\/p>\n\n\n\n<p>To do that, we find the length of the array, minus one because we are a zero-based array, and then take away the position of the current index. The array[swapIndex] we return essentially takes the place of the current index. This gives us an array of reversed characters in a string.<br><\/p>\n\n\n\n<p>The final thing we need to do is join the array together into a string and return it.&nbsp;<br><\/p>\n\n\n\n<p>Test out the solution in the code editor!<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n   &lt;head&gt;\n       &lt;meta charset=&quot;utf-8&quot; \/&gt;\n       &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot; \/&gt;\n       &lt;title&gt;&lt;\/title&gt;\n       &lt;meta name=&quot;description&quot; content=&quot;&quot; \/&gt;\n       &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot; \/&gt;\n       &lt;link rel=&quot;stylesheet&quot; href=&quot;&quot; \/&gt;\n       &lt;script&gt;\n           function reverseString(str) {\n               let newArr = str.split('');\n               let rev = newArr.map((letter, index, array) =&gt; {\n                   let newIndex = array.length - index - 1;\n                   return array[newIndex];\n               });\n               return rev.join('')\n           }\n           function showInput(e) {\n               e.preventDefault();\n               const inputStr = document.getElementById('user_input').value;\n               if(inputStr.length &lt; 1) {\n                   alert(&quot;Must enter a string to reverse. Try again.&quot;)\n               }\n               let reversed = reverseString(inputStr);\n \n               document.getElementById(\n                   'display'\n               ).innerHTML = reversed;\n               document.getElementById('user_input').value = '';\n           }\n       &lt;\/script&gt;\n       &lt;style&gt;\n           * {\n               box-sizing: border-box;;\n           }\n           body {\n               width: 100%;\n               max-width: 500px;\n               height: 100vh;\n               background: lightblue;\n               margin: 0 auto;\n               display: flex;\n               flex-flow: column wrap;\n               align-items: center;\n               justify-content: center;\n           }\n           div {\n               display: flex;\n               flex-flow: column wrap;\n               align-items: flex-start;\n               width: 100%;\n           }\n           form {\n               display: flex;\n               flex-flow: column wrap;\n               width: 100%;\n               background: lightgray;\n               padding: 20px;\n               border: 5px double slategray;\n \n \n           }\n           #user_input {\n               width: 100%;\n           }\n           #submit_button {\n               width: 25%;\n               align-self: flex-end;\n               margin-top: 10px;\n           }\n           #display {\n               font-size: 1.4rem;\n               height: 50px;\n           }\n       &lt;\/style&gt;\n   &lt;\/head&gt;\n   &lt;body&gt;\n       &lt;div&gt;\n           &lt;form onsubmit=&quot;showInput(event);&quot;&gt;\n               &lt;label id=&quot;label&quot;&gt;Enter a String to Reverse:&lt;\/label&gt;\n               &lt;input type=&quot;text&quot; name=&quot;message&quot; id=&quot;user_input&quot;\/&gt;\n               &lt;input type=&quot;submit&quot; onclick=&quot;showInput(event);&quot; id=&quot;submit_button&quot;\/&gt;&lt;br \/&gt;\n               &lt;label&gt;Your input: &lt;\/label&gt;\n               &lt;p&gt;&lt;span id=&quot;display&quot;&gt;&lt;\/span&gt;&lt;\/p&gt;\n           &lt;\/form&gt;\n          \n          \n       &lt;\/div&gt;\n   &lt;\/body&gt;\n&lt;\/html&gt;<\/pre><\/div>\n\n\n\n<p>The big thing to remember is that map returns a new array \u2013 so we are not modifying the original str\/array passed in.&nbsp;<br><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Solution #3: Built-in JavaScript Method<\/h4>\n\n\n\n<p>This method of solving this code challenge uses the built in functions\/methods <code>split()<\/code>, <code>reverse()<\/code>, and <code>join()<\/code> to solve it in this one-liner:&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>function reverseString(str) {\n               return str.split('').reverse().join('');\n           }<\/pre><\/div>\n\n\n\n<p>Try running the code below and testing it out for yourself to see it work!<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n   &lt;head&gt;\n       &lt;meta charset=&quot;utf-8&quot; \/&gt;\n       &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot; \/&gt;\n       &lt;title&gt;&lt;\/title&gt;\n       &lt;meta name=&quot;description&quot; content=&quot;&quot; \/&gt;\n       &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot; \/&gt;\n       &lt;link rel=&quot;stylesheet&quot; href=&quot;&quot; \/&gt;\n       &lt;script&gt;\n           function reverseString(str) {\n               return str.split('').reverse().join('');\n           }\n           function showInput(e) {\n               e.preventDefault();\n               const inputStr = document.getElementById('user_input').value;\n               if(inputStr.length &lt; 1) {\n                   alert(&quot;Must enter a string to reverse. Try again.&quot;)\n               }\n               let reversed = reverseString(inputStr);\n \n               document.getElementById(\n                   'display'\n               ).innerHTML = reversed;\n               document.getElementById('user_input').value = '';\n           }\n       &lt;\/script&gt;\n       &lt;style&gt;\n           * {\n               box-sizing: border-box;;\n           }\n           body {\n               width: 100%;\n               max-width: 500px;\n               height: 100vh;\n               background: lightblue;\n               margin: 0 auto;\n               display: flex;\n               flex-flow: column wrap;\n               align-items: center;\n               justify-content: center;\n           }\n           div {\n               display: flex;\n               flex-flow: column wrap;\n               align-items: flex-start;\n               width: 100%;\n           }\n           form {\n               display: flex;\n               flex-flow: column wrap;\n               width: 100%;\n               background: lightgray;\n               padding: 20px;\n               border: 5px double slategray;\n \n \n           }\n           #user_input {\n               width: 100%;\n           }\n           #submit_button {\n               width: 25%;\n               align-self: flex-end;\n               margin-top: 10px;\n           }\n           #display {\n               font-size: 1.4rem;\n               height: 50px;\n           }\n       &lt;\/style&gt;\n   &lt;\/head&gt;\n   &lt;body&gt;\n       &lt;div&gt;\n           &lt;form onsubmit=&quot;showInput(event);&quot;&gt;\n               &lt;label id=&quot;label&quot;&gt;Enter a String to Reverse:&lt;\/label&gt;\n               &lt;input type=&quot;text&quot; name=&quot;message&quot; id=&quot;user_input&quot;\/&gt;\n               &lt;input type=&quot;submit&quot; onclick=&quot;showInput(event);&quot; id=&quot;submit_button&quot;\/&gt;&lt;br \/&gt;\n               &lt;label&gt;Your input: &lt;\/label&gt;\n               &lt;p&gt;&lt;span id=&quot;display&quot;&gt;&lt;\/span&gt;&lt;\/p&gt;\n           &lt;\/form&gt;\n          \n          \n       &lt;\/div&gt;\n   &lt;\/body&gt;\n&lt;\/html&gt;<\/pre><\/div>\n\n\n\n<p>Essentially what the built-in <code>reverse()<\/code> method does is the <code>map()<\/code> method (the method we outlined in our previous solution) under the hood; <strong><em>however<\/em><\/strong>, it mutates the original array instead of returning a new one since it reverses <em>in place<\/em>. If you are solving a bigger problem, you may need to create a copy of the original array so you can still access the original if needed.&nbsp;<br><\/p>\n\n\n\n<p>These are not the only definitive ways to solve this problem \u2013 these are just some of the more popular ways to solve it. Experiment and see if you can find other solutions for yourself in the code editor above. Just edit the <code>reverseString()<\/code> function and nothing else if you would like to see it on screen.&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"One of the first code\/algorithm challenges that we set out to solve as budding software engineers and web developers is to see if we can figure out how to reverse a string. Remember that a string is just a collection of characters and spaces. What we need to set out to do is to try&hellip;","protected":false},"author":77,"featured_media":19018,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11933],"tags":[],"class_list":{"0":"post-19017","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-javascript"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"JavaScript","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>JavaScript Reverse String Code Challenge | Career Karma<\/title>\n<meta name=\"description\" content=\"One of the first code challenges encountered as a JS student is reversing a string. Let\u2019s take a look at the common ways to solve that problem in JavaScript.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Reverse String Code Challenge\" \/>\n<meta property=\"og:description\" content=\"One of the first code challenges encountered as a JS student is reversing a string. Let\u2019s take a look at the common ways to solve that problem in JavaScript.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-06T21:16:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-12-29T21:41:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Christina Kopecky\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Christina Kopecky\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-reverse-string\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-reverse-string\\\/\"},\"author\":{\"name\":\"Christina Kopecky\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\"},\"headline\":\"JavaScript Reverse String Code Challenge\",\"datePublished\":\"2020-07-06T21:16:40+00:00\",\"dateModified\":\"2020-12-29T21:41:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-reverse-string\\\/\"},\"wordCount\":715,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-reverse-string\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg\",\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-reverse-string\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-reverse-string\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-reverse-string\\\/\",\"name\":\"JavaScript Reverse String Code Challenge | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-reverse-string\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-reverse-string\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg\",\"datePublished\":\"2020-07-06T21:16:40+00:00\",\"dateModified\":\"2020-12-29T21:41:15+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\"},\"description\":\"One of the first code challenges encountered as a JS student is reversing a string. Let\u2019s take a look at the common ways to solve that problem in JavaScript.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-reverse-string\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-reverse-string\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-reverse-string\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg\",\"width\":1020,\"height\":680,\"caption\":\"Software Engineer Codes at Computer\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-reverse-string\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript Reverse String Code Challenge\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\",\"name\":\"Christina Kopecky\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"caption\":\"Christina Kopecky\"},\"description\":\"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.\",\"sameAs\":[\"http:\\\/\\\/www.linkedin.com\\\/in\\\/cmvnk\"],\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/christina-kopecky\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"JavaScript Reverse String Code Challenge | Career Karma","description":"One of the first code challenges encountered as a JS student is reversing a string. Let\u2019s take a look at the common ways to solve that problem in JavaScript.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Reverse String Code Challenge","og_description":"One of the first code challenges encountered as a JS student is reversing a string. Let\u2019s take a look at the common ways to solve that problem in JavaScript.","og_url":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-06T21:16:40+00:00","article_modified_time":"2020-12-29T21:41:15+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg","type":"image\/jpeg"}],"author":"Christina Kopecky","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"Christina Kopecky","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/"},"author":{"name":"Christina Kopecky","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"headline":"JavaScript Reverse String Code Challenge","datePublished":"2020-07-06T21:16:40+00:00","dateModified":"2020-12-29T21:41:15+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/"},"wordCount":715,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/","url":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/","name":"JavaScript Reverse String Code Challenge | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg","datePublished":"2020-07-06T21:16:40+00:00","dateModified":"2020-12-29T21:41:15+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"description":"One of the first code challenges encountered as a JS student is reversing a string. Let\u2019s take a look at the common ways to solve that problem in JavaScript.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg","width":1020,"height":680,"caption":"Software Engineer Codes at Computer"},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/javascript-reverse-string\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/careerkarma.com\/blog\/javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript Reverse String Code Challenge"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e","name":"Christina Kopecky","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","caption":"Christina Kopecky"},"description":"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.","sameAs":["http:\/\/www.linkedin.com\/in\/cmvnk"],"url":"https:\/\/careerkarma.com\/blog\/author\/christina-kopecky\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=19017"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19017\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/19018"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=19017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=19017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=19017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}