mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 01:18:23 +08:00
Merge pull request #533 from Khez/string-reverse-words
#142 #461 Adding Doctests to String/ReverseWords.js
This commit is contained in:
@ -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) => {
|
const reverseWords = (str) => {
|
||||||
if (typeof str !== 'string') {
|
if (typeof str !== 'string') {
|
||||||
throw new TypeError('The given value is not a string')
|
throw new TypeError('The given value is not a string')
|
||||||
|
Reference in New Issue
Block a user