36
4
Title stolen inspired by Greg Hewgill's answer to What's the difference between JavaScript and Java?
Introduction
Java and JavaScript are commonly used languages among programmers, and are currently the most popular tags on Stack Overflow. Yet as we all know, aside from similar names, the two have almost nothing in common.
In honor of one of programming's most infamous debates, and inspired by my recent frustrations in tag searching, I propose the following:
Challenge
Write a program which takes in a string as input. Return car
if the string begins with "Java" and does not include "JavaScript". Otherwise, return carpet
.
Example Input and Output
car:
java
javafx
javabeans
java-stream
java-script
java-8
java.util.scanner
java-avascript
JAVA-SCRIPTING
javacarpet
carpet:
javascript
javascript-events
facebook-javascript-sdk
javajavascript
jquery
python
rx-java
java-api-for-javascript
not-java
JAVASCRIPTING
Notes
- Input matching should be case insensitive
- Only possibilities for output should be
car
orcarpet
- Imaginary bonus points if your answer uses Java, JavaScript, or Regex
- Alternate Title: Java is to JavaScript as ham is to hamster
2The new [tag:pattern-matching] tag needs a wiki. Please contribute if you can – Christopher – 2017-07-13T16:29:52.737
2Depending on the order things are done in,
javacarpet
might catch bugs that the existing test cases don't. – Ray – 2017-07-13T21:17:27.52317If you get
imaginary bonus points if your answer uses Java, Javascript, or Regex
, does that make such solution's bytecount complex? ;) – Steadybox – 2017-07-13T21:34:08.787Alternate Title: Java is to JavaScript as ham is to hamster
Actually, the "ham" in "hamster" is cognate to the food "ham". The food "ham" is pig meat, and the term "hamster" is derived from the related animal, the guinea pig, whose meat replaced pigs meat on long sea voyages as the animals were easier to raise on a ship. – dotancohen – 2017-07-17T08:14:30.307