Created
November 3, 2018 14:35
-
-
Save themgoncalves/2d4967b7b2a2112da1645056ac83ea06 to your computer and use it in GitHub Desktop.
Reverse a sentence in a most perfomatic way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Reverse sentence | |
| * @function | |
| * @description Benchmark test <http://jsben.ch/8jGJ6> | |
| * @param {String} sentence - Sentence to be reversed | |
| * @return {String} reversed sentence | |
| */ | |
| const reverse = (sentence) => sentence.split(' ').reverse().join(' '); | |
| // ------------------------------------------------------ | |
| // Implementation example | |
| const sentence = 'This is a sentence of any kind'; | |
| console.log(reverse(sentence)); | |
| // will output "kind any of sentence a is This" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment