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

1928 у кіно

Захаров Федір Захарович

Ель Греко