#142 #461 Adding Doctests to String/ReverseWords.js

This commit is contained in:
Cristian Lupu
2020-10-30 18:17:57 +02:00
parent 2190b92e1b
commit 50091d299f

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')