edit-article
Home
Up
Delete
Article Name:
Article Description:
code-quiz-question - "reverse the words in a string" -
Chapter ID/Name:
Status:
Write
Writing
Written
Add Photo:
Owner ID:
Content:
use HTML
Edit Content
<h1 style="text-align: center;">reverse the words in a string</h1> <h2>[WHAT]</h2> <ol> <li><strong>] test was "reverse the words in a string"</strong></li> <ol> <li>] my thinking to create a solution was to use the split function on the 'space' char to create an arrary of words out of the string,</li> <li>] then print out the array from the last item to the first item</li> </ol></ol> <h2>[WHY]</h2> <ol> <li>] </li> </ol> <h2>[WHERE]</h2> <ol> <li>]</li> </ol> <h2>[WHEN]</h2> <ol> <li>]</li> </ol> <h2>[EXAMPLE]</h2> <ol> <li>]</li> </ol> <div><span style="font-size: medium;">let reverseWords = function(stringToReverse){</span></div> <div> </div> <div><span style="font-size: medium;"> // array likely has a method to reverse the elements, but will use my own iteration</span></div> <div><span style="font-size: medium;"> var wordArray = stringToReverse.split(' ');</span></div> <div><span style="font-size: medium;"> var reversedString ="";</span></div> <div><span style="font-size: medium;"> for ( i= wordArray.length, i >= 0, i--){</span></div> <div><span style="font-size: medium;"> reversedString += wordArray[i]+' ';</span></div> <div><span style="font-size: medium;"> }</span></div> <div><span style="font-size: medium;"> return reversedString;</span></div> <div><span style="font-size: medium;">}</span></div> <h2>[HOW-TO]</h2> <ol> <li>]</li> </ol> <h2>[REFERENCE]</h2> <ol> <li>[] src =</li> </ol> <p> </p> <p> </p> <p> </p>