textconvert
Version:
Public library to convert text into many conventions and formats.
16 lines (15 loc) • 468 B
JavaScript
/**
* Reverses all characters in a string.
* @param text A string to reverse.
* @returns Reversed string.
* @example
* reverse('Hello, world!'); // '!dlrow ,olleH'
*/
export function reverse(text) {
// return type is inferred
// Make sure input is valid
if (!text)
return 'Please provide a valid input text';
// Split string into characters, reverse all of them and join them back together
return text.split('').reverse().join('');
}