Timeline for Elegant function to "increase" a JavaScript string - for example, turning "aac" into "aad"
Current License: CC BY-SA 3.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Feb 28, 2013 at 9:08 | comment | added | SylvainD | Please note that the current implementation doesn't handle edge case properly. What do you want inc_str('z') to be for instance ? | |
Feb 24, 2013 at 17:46 | comment | added | MaiaVictor | I'm finishing my work and will post it on Github probably by march 15, I've made a note to update you guys then! | |
Feb 24, 2013 at 2:55 | comment | added | copy | @Dokkat yes please | |
Feb 24, 2013 at 1:03 | comment | added | MaiaVictor | @radarbob that's not the point, the system won't accept statements and variable definitions. Notice everything is an expression. This is analyzed by the AI. Are you curious to see it? | |
Feb 24, 2013 at 0:53 | history | edited | Joseph | CC BY-SA 3.0 |
deleted 57 characters in body
|
Feb 23, 2013 at 19:14 | comment | added | radarbob | @Dokkat, so you wrote it with your eyes closed? | |
Feb 23, 2013 at 18:12 | comment | added | MaiaVictor | That's fine, this isn't meant to be human readable as it is the base of an AI programming system I'm developing. Less tokens = better and I must avoid varaibles. | |
Feb 23, 2013 at 17:49 | comment | added | copy | @Dokkat you shouldn't write your code so condensed. | |
Feb 23, 2013 at 17:42 | vote | accept | MaiaVictor | ||
Feb 23, 2013 at 17:42 | comment | added | MaiaVictor |
Yay I'm glad I motivated someone to joining in. Great way to start, also. That was the obvious thing I was missing, recursion! Adapting from your answer, I got the one-liner: function inc_str(str){ return (last(str) == "z") ? inc_str(head(str)) + "a" : head(str) + inc_char(last(str)); }; So elegant! Thank you.
|
|
Feb 23, 2013 at 17:41 | review | First posts | |||
Feb 23, 2013 at 17:54 | |||||
Feb 23, 2013 at 17:27 | review | Suggested edits | |||
Feb 23, 2013 at 17:28 | |||||
Feb 23, 2013 at 17:26 | comment | added | Benjamin Gruenbaum | Hah! You couldn't resist opening an account just for this :) | |
Feb 23, 2013 at 17:22 | history | answered | copy | CC BY-SA 3.0 |