Skip to content

Instantly share code, notes, and snippets.

@themgoncalves
Created November 3, 2018 14:35
Show Gist options
  • Save themgoncalves/2d4967b7b2a2112da1645056ac83ea06 to your computer and use it in GitHub Desktop.
Save themgoncalves/2d4967b7b2a2112da1645056ac83ea06 to your computer and use it in GitHub Desktop.
Reverse a sentence in a most perfomatic way
/*
* 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