36
6
The Task
In this challenge, your task is to write a program or function which takes in a String and outputs a truthy or falsey value based on whether the first character and the last character of the input String are equal.
Input
You may take input in any way reasonable way. However, assuming that the input is present in a predefined variable is not allowed. Reading from a file, console, command line, input field etc., or taking input as a function argument is allowed.
Output
You may output in any reasonable format, except for assigning the result to a variable. Writing to a file, console, command line, modal box, function return
statements etc. is allowed.
Additional Rules
The input can be empty String as well, for which you should return a falsey value.
Single-Char Input Strings should have a truthy result.
Your program should be case-sensitive.
helloH
should output a falsey value.You can only have a single Truthy value and a single Falsey value. For example, outputting
false
for an Input String and0
for another input String as Falsey values is not allowed.Standard loopholes are not allowed.
Test Cases
Input -> Output
"10h01" Truthy
"Nothing" Falsey
"Acccca" Falsey
"wow!" Falsey
"wow" Truthy
"H" Truthy
"" Falsey
This is code-golf, so the shortest code in bytes wins!
What characters can appear in the input? Printable ASCII? – Martin Ender – 2017-05-13T19:35:12.627
@MartinEnder Printable ASCII. Although, I don't think it matters much. – Arjun – 2017-06-03T17:29:44.120
Of course it matters. Some languages can't process non-ASCII characters or null bytes, and in a regex I can match any printable ASCII character with
.
, but it wouldn't match linefeeds. In general, if you find yourself using the [tag:string] tag, specify exactly what characters can appear in the input. – Martin Ender – 2017-06-03T17:31:55.477@MartinEnder Okay. Will take care in future. – Arjun – 2017-06-04T07:16:24.867
Suggested test case:
AbAb => false
– caird coinheringaahing – 2017-10-31T14:40:12.613