Quote:
i can't find solution online
Just Googling on internet is not your job, as programmer, your job is to create algorithms.
The algorithm great lines are:
- Scan the input for sequences of digits
- For each sequence, replace it with the reverse
To help you analyze problems, you should learn one or more analyze methods,
E.W. Djikstra top-Down method is a good start.
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[
^]
https://en.wikipedia.org/wiki/Structured_programming[
^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[
^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[
^]
For this problem, RegEx (Regular Expression) can greatly simplify the code. RegEx are used to match sequences in strings and to do things with matches like replacing them in string.
JavaScript RegExp Object[
^]
Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[
^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[
^]
Expresso Regular Expression Tool[
^]
RegExr: Learn, Build, & Test RegEx[
^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[
^]
Note: This code is over complicated:
function myfunction(a){
var x=a.toString();
var y= x.split(" ");
you convert
a
to string, but it is already a string, so this code can be simplified to:
function myfunction(a){
var y= a.split(" ");
Here
myfunction( "Dlasdf234dkl sdfkl8886adaf15adfjk7 asdflkj376661a s445s198");
you forgot to do something with the result of myfunction.
result= myfunction( "Dlasdf234dkl sdfkl8886adaf15adfjk7 asdflkj376661a s445s198");