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:
parent
a70a2503ab
commit
6872bab0de
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue