Skip to content

Instantly share code, notes, and snippets.

@johntran
Last active April 10, 2016 02:16
Show Gist options
  • Save johntran/a96385d23d7a2c83667bfaa4ce82ec87 to your computer and use it in GitHub Desktop.
Save johntran/a96385d23d7a2c83667bfaa4ce82ec87 to your computer and use it in GitHub Desktop.
// basically it asks to create a function that reverse the whole string without reverse the positions of the words.
// "Three Blind mice"
// "eerhT dnilB ecim"
var stringToArray = function (str) {
return str.split(' ')
}
// ['Three', 'Blind', 'mice']
var reverseElementsInArray = function (arr) {
return arr.map(function(element) {
return element.split('')
.reverse()
.join('')
})
}
// ['eerhT', 'dnilB', 'ecim']
var arrayToSentence = function (arr) {
return arr.join(' ')
}
// "eerhT dnilB ecim"
var oneLiner = function (str) {
return str.split(' ')
.map(function(element) {
return element.split('')
.reverse()
.join('')
})
.join(' ')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment