functionremoveQuestionMarks(input){if(typeofinput!=="string"){thrownewTypeError("First argument expected to be a string");}returninput.split("?").join("");}console.log(removeQuestionMarks("hello?"));// "hello"console.log(removeQuestionMarks("hmm? hello??"));// "hmm hello"console.log(removeQuestionMarks("hmm? hello?? can i speak to the manager?"));// "hmm hello can i speak to the manager"console.log(removeQuestionMarks("?? is anybody there???"));// " is anybody there"
By the name of the title in my notifications, I really though that the challenge would be to write a challenge and submit the best to the Dev.to team as they were running out of ideas. Haha!
By the name of the title in my notifications, I really though that the challenge would be to write a challenge and submit the best to the Dev.to team as they were running out of ideas. Haha!
Please submit challenge ideas! Simply email yo+challenge@dev.to with any proposals and we'll give you credit when we post it :)
/*
* bsure - remove question marks from a string
* if dst and src overlap (or match), that's fine
* returns the number of bytes copied (including the null byte).
*/
size_t bsure(char *dst, char *src);
// CharacterRemover.javapackageorg.stringops.questionmarkremover;publicinterfaceCharacterRemover{/**
* TODO
* @param String source TODO
* @return String TODO
*/publicStringremoveCharacter(Stringsource);}
// CharacterRemoverFactory.javapackageorg.stringops.questionmarkremover;publicinterfaceCharacterRemoverFactory{/**
* TODO
* @return CharacterRemover TODO
*/publicCharacterRemovercreateCharacterRemover();}
// QuestionMarkRemover.javapackageorg.stringops.questionmarkremover;importjava.io.StringReader;importjava.io.InputStreamReader;importjava.io.ByteArrayOutputStream;importjava.io.IOException;publicclassQuestionMarkRemoverimplementsCharacterRemover{/**
* TODO
* @param String source TODO
* @return String TODO
*/publicStringremoveCharacter(Stringsource){StringReaderreader=newStringReader(source);ByteArrayOutputStreamoutputStream=newByteArrayOutputStream();try{intdataFromReader=reader.read();while(dataFromReader!=-1){if(dataFromReader!='?'){outputStream.write(dataFromReader);}dataFromReader=reader.read();}}catch(IOExceptione){// TODO: handle the exception}byte[]byteArray=outputStream.toByteArray();returnnewString(byteArray);}}
// QuestionMarkRemoverFactory.javapackageorg.stringops.questionmarkremover;publicclassQuestionMarkRemoverFactoryimplementsCharacterRemoverFactory{/**
* TODO
* @return CharacterRemover TODO
*/publicCharacterRemovercreateCharacterRemover(){returnnewQuestionMarkRemover();}}
And to use it:
importorg.stringops.questionmarkremover.*;publicclassApp{/**
* TODO
* @param String[] args TODO
* @return void TODO
*/publicstaticvoidmain(String[]args){CharacterRemoverFactorycharacterRemoverFactory=newQuestionMarkRemoverFactory();CharacterRemovercharacterRemover=characterRemoverFactory.createCharacterRemover();System.out.println(characterRemover.removeCharacter("hello?"));}}
19 yo student *and* a full-time developer.
Building with Rails currently, exploring new frontiers.
I enjoy functional programming, Linux, FOSS, refactoring and mentoring :)
Okay, I'll bite and imagine that Carmen Sandiego has stolen all the regular expressions!
defmoduleDarnYouCarmendo# Quick, destroy the question marks before she steals them, too!defwhats_a_question(string,processed\\[])defwhats_a_question("",processed),do:IO.chardata_to_binary(processed)defwhats_a_question("?"<>string,processed),do:whats_a_question(string,processed)defwhats_a_question(<<next::utf8>><>string,processed),do:whats_a_question(string,[processed,next]endDarnYouCarmen.whats_a_question("What is this? What's happening??")# "What is this What's happening"
Uses a simple regular expressions with the global (g) modifier to find all the ? (this needs to be escaped in a regular expression, so \?) and replace them with the empty string ''.
The tr operator works like the tr shell util. /d means non-replaced characters are deleted, /r returns the value instead of modifying the bound variable.
I've never had the courage to deep dive into the Fish shell honestly but your comment gave me some strength. I'll fire up a Docker container to test it out. Added to my ToDo list! Thanks.
Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
Hey there! Nice to see some bash users here.
You can even use bash without sed using this little trick:
Try it online.
See Manipulating String.
ruby <3
JavaScript
Here is my take to the challenge:
Source-Code
Available online.
Side-note
By the name of the title in my notifications, I really though that the challenge would be to write a challenge and submit the best to the Dev.to team as they were running out of ideas. Haha!
Please submit challenge ideas! Simply email yo+challenge@dev.to with any proposals and we'll give you credit when we post it :)
Tomorrows challenge:
Oh, sounds sexy. I love it! Haha.
x86_64 assembly (System V ABI, GNU assembler), as usual:
bsure.S:
bsure.h:
Javascript:
Called as:
Important to note, this will also remove the first escape characters (
\) and output newlines in template literals as\nRust
Playground
And to use it:
NOOOO!!!
You need to create an instance of the
OpinionAboutJavaFactory! You can just have a staticgetOpinionAboutJavamethod! Now your code is not SOLID!ENTERPRISE
... 😐
I mean... that's not even a function to write. It's a function to call.
Elixir:
Ruby:
JavaScript:
Bash:
Okay, I'll bite and imagine that Carmen Sandiego has stolen all the regular expressions!
(javascript)
Uses a simple regular expressions with the global (
g) modifier to find all the?(this needs to be escaped in a regular expression, so\?) and replace them with the empty string''.Ruby
sedis overkill. Trytr:This one works for me. Since Bash doesn't support the global flag for regular expressions I had to iterate over the input string...
Try
trinstead. 😁Perl solution:
The
troperator works like thetrshell util./dmeans non-replaced characters are deleted,/rreturns the value instead of modifying the bound variable.PHP :
Hey there! Awesome to see some PHP users. PHP IS NOT DEAD! Haha.
But you are halfway done buddy!
okay okay let's do a wrapper function then :D
That function name tho. haha!
Even though this is a simple one - it's really interesting to see all of the different ways you can do it!
But I agree with Josh - it's built into most languages :)
I see. Also
%literal is my favorite string literal :)Haskell:
Similar in Elm (but we have to use wrapping parenthesis for binary operators).
I love weird Ruby syntax😆
TIPS:
??is known as character literal notationdocs.ruby-lang.org/en/trunk/syntax...
I've never had the courage to deep dive into the Fish shell honestly but your comment gave me some strength. I'll fire up a Docker container to test it out. Added to my ToDo list! Thanks.
PHP:
My solution in js
Well, since we're doing cmd things...
(bash on mac)
I intentionally avoided using
sedthis time, wanted to implement it with "pure" Bash. Usingsedthe implementation, of course, becomes much shorter.`
Python:
Python
As simple as it sounds, in python :