From 2f93862621a738e40980ed07c8d786a54dea93a4 Mon Sep 17 00:00:00 2001 From: David Wu Date: Sun, 24 Dec 2017 14:44:26 +0100 Subject: [PATCH 1/2] Correct faults Your version didn't work. There was a declaration fault alongside with an identifier fault as Array.forEach does not return anything. --- snippets/toKebabCase.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/snippets/toKebabCase.md b/snippets/toKebabCase.md index 5e482426d..0e3fd0a3c 100644 --- a/snippets/toKebabCase.md +++ b/snippets/toKebabCase.md @@ -14,11 +14,9 @@ For more detailed explanation of this Regex [Visit this Site](https://regex101.c ```js const toKebabCase = str => { let regex = rx = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g; - let arr = str.match(regex); - arr = arr.forEach(x =>{ - return s.toLowerCase(); - }); - return arr.join('-') + return str.match(regex).map(x =>{ + return x.toLowerCase(); + }).join('-'); } // toKebabCase("camelCase") -> 'camel-case' // toKebabCase("some text") -> 'some-text' From 118c7e9e7b386b9659a03aef7b44ccaace71cc4c Mon Sep 17 00:00:00 2001 From: David Wu Date: Sun, 24 Dec 2017 14:45:17 +0100 Subject: [PATCH 2/2] Update toKebabCase.md --- snippets/toKebabCase.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/toKebabCase.md b/snippets/toKebabCase.md index 0e3fd0a3c..78294e993 100644 --- a/snippets/toKebabCase.md +++ b/snippets/toKebabCase.md @@ -22,5 +22,5 @@ const toKebabCase = str => { // toKebabCase("some text") -> 'some-text' // toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens' // toKebabCase("AllThe-small Things") -> "all-the-small-things" -// toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLandHTML') -> "i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-xml-and-html" +// toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') -> "i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-xml-and-html" ```