Update snakeCase.js

hello; it will be a great honor to contribute in this exercise solution;
1. I think it is better to replace the "-" with a space "  " in the beginning because that will create some mistakes when  - come with an uppercase letter "-A" .

2. replace the "__" by "_" at the end because if ".." come with "-"  or with uppercase will create two underscores.
              
I hope this helps , thank you .
This commit is contained in:
othman-19 2019-03-07 18:24:48 +01:00 committed by GitHub
parent a70a2503ab
commit 6872bab0de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -1,6 +1,6 @@
const snakeCase = function(string) { const snakeCase = function(string) {
// wtf case // wtf case
string = string.replace(/\.\./g, " "); string= string.replace(/[(\.\.)-]/g, " ");
// this splits up camelcase IF there are no spaces in the word // this splits up camelcase IF there are no spaces in the word
if (string.indexOf(" ") < 0) { if (string.indexOf(" ") < 0) {
@ -13,7 +13,8 @@ const snakeCase = function(string) {
.replace(/[,\?\.]/g, "") .replace(/[,\?\.]/g, "")
.replace(/\-/g, " ") .replace(/\-/g, " ")
.split(" ") .split(" ")
.join("_"); .join("_")
.replace(/(__)/g,'_');
}; };
module.exports = snakeCase; module.exports = snakeCase;