Today's challenge is to write a function that when given a string returns the string with the characters in the reverse order.
E.g.
reverseString('hello');
//output: 'olleh'
But instead of trying to make a nice shiny function, write something bad. Throw space and time optimisations out the window. Double down on cyclomatic complexity. Make the compiler sad.
Tests
reverseString('Use Markdown to write and format posts.') == '.stsop tamrof dna etirw ot nwodkraM esU';
reverseString('You can use Liquid tags to add rich content such as Tweets, YouTube videos, etc.') == '.cte ,soediv ebuTuoY ,steewT sa hcus tnetnoc hcir dda ot sgat diuqiL esu nac uoY';
reverseString('In addition to images for the post\'s content, you can also drag and drop a cover image') == 'egami revoc a pord dna gard osla nac uoy ,tnetnoc s\'tsop eht rof segami ot noitidda nI';
reverseString('') == '';
Top comments (18)
Why not use Python's [::-1], but entirely in the browser? We can load the Pyodide runtime so we can run Python in the browser through WebAssembly. We'll have to eval as no ES module is shipped, but surely that's not a problem. Also the runtime is 20MB, but it's worth it!
Copy it into your browser console and be amazed..
Just shuffle the characters and see if it reversed the string! We'll get the reverse eventually.... (prepare to wait a long time for strings longer than 8 characters)
Perfect!
I'm loving this. Here my attempt:
This is my favorite so far. The reversed signatures are a nice touch
Thanks! Felt very meta some how.
My humble submission:
❤️ this challenge
This solution is inspired by my_first_calculator.py. It works for all lowercase alphabetic strings of length 3. The generated (non-
eval
ed) version is 17,582 lines of code.When I open the "my_first_calculator.py" file it took so long, I thought something was wront with the git site ou my internet was down. Then I saw the file and I understood
so easy
this works for any amount of chars xd
We need a computer network.
WEDIDIT 🎉
I am too lazy to implement the reverse function so I made cursed version instead.
Ok, so this monstrosity uses the built-in
substr
method. But instead of using that to determine the string, it builds a whole bund of PHP code to execute within the shell, calls that via exec, and returns the string.Awfully bad practice, inefficient, and dangerous. It's the type of code which gives PHP a bad name!