Merge pull request #533 from Khez/string-reverse-words

#142 #461 Adding Doctests to String/ReverseWords.js
This commit is contained in:
marsonya
2021-01-20 20:41:24 +05:30
committed by GitHub

View File

@ -1,3 +1,19 @@
/*
* Doctests
*
* > reverseWords('I Love JS')
* 'JS Love I'
* > reverseWords('Hello World')
* 'World Hello'
* > reverseWords('The Algorithms Javascript')
* 'Javascript Algorithms The'
* > reverseWords([])
* ! TypeError
* > reverseWords({})
* ! TypeError
* > reverseWords(null)
* ! TypeError
*/
const reverseWords = (str) => {
if (typeof str !== 'string') {
throw new TypeError('The given value is not a string')