How do you get a string to a array in JavaScript? [on hold]2019 Community Moderator ElectionWhat is the difference between String and string in C#?How to validate an email address in JavaScript?How do JavaScript closures work?How do you get a timestamp in JavaScript?How do I check if an array includes an object in JavaScript?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?

Why aren't there more Gauls like Obelix?

Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?

Where is the License file location for Identity Server in Sitecore 9.1?

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

How can I have x-axis ticks that show ticks scaled in powers of ten?

Why does a car's steering wheel get lighter with increasing speed

Did Amazon pay $0 in taxes last year?

How strong is the axiom of well-ordered choice?

What is Tony Stark injecting into himself in Iron Man 3?

How to distinguish easily different soldier of ww2?

PTIJ: Sport in the Torah

The (Easy) Road to Code

Why is there an extra space when I type "ls" on the Desktop?

Why would /etc/passwd be used every time someone executes `ls -l` command?

Is this Paypal Github SDK reference really a dangerous site?

How does learning spells work when leveling a multiclass character?

Can Witch Sight see through Mirror Image?

Professor forcing me to attend a conference, I can't afford even with 50% funding

Averaging over columns while ignoring zero entries

I am the person who abides by rules but breaks the rules . Who am I

Do I need a return ticket to Canada if I'm a Japanese National?

What does *dead* mean in *What do you mean, dead?*?

Is this a crown race?

Boss Telling direct supervisor I snitched



How do you get a string to a array in JavaScript? [on hold]



2019 Community Moderator ElectionWhat is the difference between String and string in C#?How to validate an email address in JavaScript?How do JavaScript closures work?How do you get a timestamp in JavaScript?How do I check if an array includes an object in JavaScript?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?










-6















How do you get a string to a array in JavaScript?



I'm thinking getting a string like '146/1A Nguyen Che Nghia quan 8' to the array [146, /, 1, A, Nguyen Che Nghia quan, 8]



My solution:



var s = ' 146/1A Nguyễn Chế Nghĩa quận 8';


function name(string)
var reg = /[0-9]*d/g;

var splited = string.trim().split(' ');
console.log(splited);

var joined = splited.reduce((acc, cur)=>
reg.test(cur)?
acc.push(cur):
reg.test(acc[acc.length-1])?
acc.push(cur):
acc[acc.length-1] += (" " + cur);
return acc;
,[]);
console.log(joined);

var splitedNumber = joined.map((val)=>
if(!reg.test(val)) return val;

var listNumber = val.match(reg);
var splited = val.replace(reg,"00").split("0");

!splited[splited.length-1] && splited.pop();
!splited[0] && splited.shift();

return splited.reduce((acc,cur)=>
acc.push(!cur ? listNumber.shift() : cur);
return acc;
,[]);
);
console.log(splitedNumber);

return splitedNumber.reduce((acc,val)=>
reg.test(val)? acc.push(...val): acc.push(val);
return acc,[])



console.log(name(s));

//[146,/,1,A, NGuyễn Chế Nghĩa quận, 8]


It's so bad. Please help me the best solution



Many thanks










share|improve this question









New contributor




Hữu Trương Nguyễn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as too broad by Wiktor Stribiżew, Keith, Toto, Nicholas K, adiga 2 days ago


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • You must have some kind of format definition or definitions of which characters can act as separators. Do you have something like that?

    – aPhilRa
    2 days ago






  • 1





    Also please provide the code you tried so far and what not working for you

    – Tamir Klein
    2 days ago











  • How much effort is expected of Stack Overflow users?

    – adiga
    2 days ago











  • jsbin.com/moyopujowe/1/…

    – Hữu Trương Nguyễn
    2 days ago















-6















How do you get a string to a array in JavaScript?



I'm thinking getting a string like '146/1A Nguyen Che Nghia quan 8' to the array [146, /, 1, A, Nguyen Che Nghia quan, 8]



My solution:



var s = ' 146/1A Nguyễn Chế Nghĩa quận 8';


function name(string)
var reg = /[0-9]*d/g;

var splited = string.trim().split(' ');
console.log(splited);

var joined = splited.reduce((acc, cur)=>
reg.test(cur)?
acc.push(cur):
reg.test(acc[acc.length-1])?
acc.push(cur):
acc[acc.length-1] += (" " + cur);
return acc;
,[]);
console.log(joined);

var splitedNumber = joined.map((val)=>
if(!reg.test(val)) return val;

var listNumber = val.match(reg);
var splited = val.replace(reg,"00").split("0");

!splited[splited.length-1] && splited.pop();
!splited[0] && splited.shift();

return splited.reduce((acc,cur)=>
acc.push(!cur ? listNumber.shift() : cur);
return acc;
,[]);
);
console.log(splitedNumber);

return splitedNumber.reduce((acc,val)=>
reg.test(val)? acc.push(...val): acc.push(val);
return acc,[])



console.log(name(s));

//[146,/,1,A, NGuyễn Chế Nghĩa quận, 8]


It's so bad. Please help me the best solution



Many thanks










share|improve this question









New contributor




Hữu Trương Nguyễn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as too broad by Wiktor Stribiżew, Keith, Toto, Nicholas K, adiga 2 days ago


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • You must have some kind of format definition or definitions of which characters can act as separators. Do you have something like that?

    – aPhilRa
    2 days ago






  • 1





    Also please provide the code you tried so far and what not working for you

    – Tamir Klein
    2 days ago











  • How much effort is expected of Stack Overflow users?

    – adiga
    2 days ago











  • jsbin.com/moyopujowe/1/…

    – Hữu Trương Nguyễn
    2 days ago













-6












-6








-6


1






How do you get a string to a array in JavaScript?



I'm thinking getting a string like '146/1A Nguyen Che Nghia quan 8' to the array [146, /, 1, A, Nguyen Che Nghia quan, 8]



My solution:



var s = ' 146/1A Nguyễn Chế Nghĩa quận 8';


function name(string)
var reg = /[0-9]*d/g;

var splited = string.trim().split(' ');
console.log(splited);

var joined = splited.reduce((acc, cur)=>
reg.test(cur)?
acc.push(cur):
reg.test(acc[acc.length-1])?
acc.push(cur):
acc[acc.length-1] += (" " + cur);
return acc;
,[]);
console.log(joined);

var splitedNumber = joined.map((val)=>
if(!reg.test(val)) return val;

var listNumber = val.match(reg);
var splited = val.replace(reg,"00").split("0");

!splited[splited.length-1] && splited.pop();
!splited[0] && splited.shift();

return splited.reduce((acc,cur)=>
acc.push(!cur ? listNumber.shift() : cur);
return acc;
,[]);
);
console.log(splitedNumber);

return splitedNumber.reduce((acc,val)=>
reg.test(val)? acc.push(...val): acc.push(val);
return acc,[])



console.log(name(s));

//[146,/,1,A, NGuyễn Chế Nghĩa quận, 8]


It's so bad. Please help me the best solution



Many thanks










share|improve this question









New contributor




Hữu Trương Nguyễn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












How do you get a string to a array in JavaScript?



I'm thinking getting a string like '146/1A Nguyen Che Nghia quan 8' to the array [146, /, 1, A, Nguyen Che Nghia quan, 8]



My solution:



var s = ' 146/1A Nguyễn Chế Nghĩa quận 8';


function name(string)
var reg = /[0-9]*d/g;

var splited = string.trim().split(' ');
console.log(splited);

var joined = splited.reduce((acc, cur)=>
reg.test(cur)?
acc.push(cur):
reg.test(acc[acc.length-1])?
acc.push(cur):
acc[acc.length-1] += (" " + cur);
return acc;
,[]);
console.log(joined);

var splitedNumber = joined.map((val)=>
if(!reg.test(val)) return val;

var listNumber = val.match(reg);
var splited = val.replace(reg,"00").split("0");

!splited[splited.length-1] && splited.pop();
!splited[0] && splited.shift();

return splited.reduce((acc,cur)=>
acc.push(!cur ? listNumber.shift() : cur);
return acc;
,[]);
);
console.log(splitedNumber);

return splitedNumber.reduce((acc,val)=>
reg.test(val)? acc.push(...val): acc.push(val);
return acc,[])



console.log(name(s));

//[146,/,1,A, NGuyễn Chế Nghĩa quận, 8]


It's so bad. Please help me the best solution



Many thanks







javascript arrays regex string algorithm






share|improve this question









New contributor




Hữu Trương Nguyễn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Hữu Trương Nguyễn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday







Hữu Trương Nguyễn













New contributor




Hữu Trương Nguyễn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Hữu Trương NguyễnHữu Trương Nguyễn

11




11




New contributor




Hữu Trương Nguyễn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Hữu Trương Nguyễn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Hữu Trương Nguyễn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as too broad by Wiktor Stribiżew, Keith, Toto, Nicholas K, adiga 2 days ago


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









put on hold as too broad by Wiktor Stribiżew, Keith, Toto, Nicholas K, adiga 2 days ago


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • You must have some kind of format definition or definitions of which characters can act as separators. Do you have something like that?

    – aPhilRa
    2 days ago






  • 1





    Also please provide the code you tried so far and what not working for you

    – Tamir Klein
    2 days ago











  • How much effort is expected of Stack Overflow users?

    – adiga
    2 days ago











  • jsbin.com/moyopujowe/1/…

    – Hữu Trương Nguyễn
    2 days ago

















  • You must have some kind of format definition or definitions of which characters can act as separators. Do you have something like that?

    – aPhilRa
    2 days ago






  • 1





    Also please provide the code you tried so far and what not working for you

    – Tamir Klein
    2 days ago











  • How much effort is expected of Stack Overflow users?

    – adiga
    2 days ago











  • jsbin.com/moyopujowe/1/…

    – Hữu Trương Nguyễn
    2 days ago
















You must have some kind of format definition or definitions of which characters can act as separators. Do you have something like that?

– aPhilRa
2 days ago





You must have some kind of format definition or definitions of which characters can act as separators. Do you have something like that?

– aPhilRa
2 days ago




1




1





Also please provide the code you tried so far and what not working for you

– Tamir Klein
2 days ago





Also please provide the code you tried so far and what not working for you

– Tamir Klein
2 days ago













How much effort is expected of Stack Overflow users?

– adiga
2 days ago





How much effort is expected of Stack Overflow users?

– adiga
2 days ago













jsbin.com/moyopujowe/1/…

– Hữu Trương Nguyễn
2 days ago





jsbin.com/moyopujowe/1/…

– Hữu Trương Nguyễn
2 days ago












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved