this seems a mix between JavaScript and i dnno what. What language is it?! or the solution must be? C++?
i dont get why it must be done with an regex replace?
I've learnt a few languages and I wouldn't say I'm even that good at them. I know the basic layout of code, how to write in code. But how do people understand it so well they can do things like this?
Basically just converts and input number to have commas every 3 numbers. Please break it down because my head is clearly too small.Code:function string sexynumber(N) { local Str = N:toString() local OldStr = Str while (1) { Str = Str:replaceRE("^(-?%d+)(%d%d%d)", "%1,%2") if (Str == OldStr) { break } OldStr = Str } return Str }
Does it just come with advanced learning or is there an easier way to understand it?
Should I be looking at other peoples codes?
this seems a mix between JavaScript and i dnno what. What language is it?! or the solution must be? C++?
i dont get why it must be done with an regex replace?
IT's a main game dude, try be easier and u understand all)
in JavaScript i would just do this:
the concept would work in other languages tooCode:function sexynumber(num) { const strNumber = num.toString(); const strLength = strNumber.length - 1; const out = []; for (let c = -1, i = strLength; i >= 0; i--) { if (isNaN(strNumber.charAt(i))) { continue; } if (++c < 3) { out.push(strNumber.charAt(i)); continue; } c = 0; out.push(','); out.push(strNumber.charAt(i)); } return out.reverse().join(''); } console.log(sexynumber(100000000000));
Str:replaceRE("^(-?%d+)(%d%d%d)", "%1,%2")
is a regular expression replacement, lets break it down
^ means start of the string
(-?%d+) is a capture group. -? means that a minus sign is optional. %d means a digit and the plus sign means 1 or more of the previous match, in this case a digit.
(%d%d%d) is another capture group. it basically captures when there are 3 digits in a row.
This regex replace will therefor only match if it can find a string of 4 or more digits, optionally prefixed by a -.
Example: 1234567890
The (-?%d+) group captures 1234567 and stores it in %1 and (%d%d%d) captures 890 and stores it in %2. The string is replaced by %1,%2 so this becomes 1234567,890
it compares 1234567,890 to 1234567890 and notices its not the same, so it repeats the regex replacement
(-?%d+) now captures 1234 and (%d%d%d) now captures 567, so 1234567,890 this is replaced by 1234,567,890
it compares 1234,567,890 to 1234567,890 and notices its not the same, so it repeats the regex replacement
(-?%d+) now captures 1 and (%d%d%d) now captures 234, so 1234,567,890 this is replaced by 1,234,567,890
it compares 1,234,567,890 to 1234,567,890 and notices its not the same, so it repeats the regex replacement
(-?%d+) now captures 1, but there are no 3 digits left for (%d%d%d) to capture, so the replace does nothing.
it compares 1,234,567,890 to 1,234,567,890 and notices its the same, so it's done replacing.
You can practice regex patterns on sites like regexr[dot]com
This follows a slightly different format though, as i'm not sure what regex flavor your example is.
If you use regexr[dot]com enable the multiline flag and use this as expression : ^(-?\d+)(\d\d\d)
In the text field add
Go to the replace tab in the bottom right and enter $1,$2Code:1234567890 1234567,890 1234,567,890 1,234,567,890
Then you'll see this example.
It also has an explanation for the regex pattern.
Last edited by Hell_Demon; 09-05-2018 at 06:40 AM.
Ah we-a blaze the fyah, make it bun dem!
fidle89 (09-10-2018)
they just practice and practice just like anything in else in life. some people go to college to learn. people will pay for in depth online courses with live help.
I'd actually oppose, this seems like bad code and that's why you can't understand it. Good code will be understandable to a beginner coder.
If the one programming that code would add comments, change the names of the variables/functions to mean something you will understand better.
(Mostly the comments part. Add comments!)
I dont think its that hard. I lived with it for 3 weeks as a beginner and could do many things without help. But yeah coding could be made easier.
I dunno, this looks a mess to me. I understand what it's saying but it could be a lot cleaner. I think one of the easiest languages that could do this for you would be PHP, or VB. Then again, jQuery is a godsend for cleaning up code.
By reading your post I get the impression you don't know a great deal which is fine, a lot of developers here are full-time developers and have it embedded into their heads 24/7. Coding isn't an art, in the sense that anyone can do it given enough time and learning. A lot of languages do more or less the same thing, except it's read different by both the computer and the human behind the screen. Take a look at some examples on Stack Overflow as that's a good website for everything. I know Codecademy was good for starters but I'm not sure what's it like nowadays.
Edit: One thing I was taught a long time ago was Psuedocode. It's a sequence that's written in standard English (or your chosen language) that is styled as code, making it easier for everyone to read. I'll suggest next time you create something, do it in psuedocode first so you can understand exactly what's happening. With this you can use selection and iteration statements as well and it'll be a hundred times easier to understand. After that, it's just a case of finding the language you want to try creating it in.
Last edited by fidle89; 09-10-2018 at 02:12 AM.
Coding requires understanding of logic
Keep doing it nigga, with experience you gain familiarity and knowledge.
![]()
THE EYE OF AN ADMINISTRATOR IS UPON YOU. ANY WRONG YOU DO IM GONNA SEE, WHEN YOU'RE ON MPGH, LOOK BEHIND YOU, 'CAUSE THATS WHERE IM GONNA BE
"First they ignore you. Then they laugh at you. Then they fight you. Then you lose.” - Dave84311
HAVING VIRTUAL DETOX
Sam (09-29-2018)
not that it matters but if you learn enough code you can hack the pentagon. If you need a VPN i'd recommend NordVPN![]()
Nah
Possibly xD
I'm in no means "an expert coder" or advanced in any sort but honestly anything i've learned is from basic common sense in understanding aswell as learning from friends, friends are like the best thing for this because you guys could review eachothers code and explanations to eachother on what does what, what goes where and why, I learned quite the few things from friends and its actually so fun to do, honestly round up a few friends that tend to code aswell and it really does help if you guys are coding the same language aswell as projects that are similar so you could see who took what path and how and why, whats more efficient etc.