33
0
(heavily inspired by Element of string at specified index)
Given a string s
and an integer n
representing an index in s
, output s
with the character at the n
-th position removed.
0-indexing and 1-indexing are allowed.
- For 0-indexing,
n
will be non-negative and less than the length ofs
. - For 1-indexing,
n
will be positive and less than or equal to the length ofs
.
s
will consist of printable ASCII characters only (\x20-\x7E
, or
through ~
).
Any reasonable input/output is permitted. Standard loopholes apply.
Testcases (0-indexed):
n s output
0 "abcde" "bcde"
1 "abcde" "acde"
2 "a != b" "a = b"
3 "+-*/" "+-*"
4 "1234.5" "12345"
3 "314151" "31451"
Testcases (1-indexed):
n s output
1 "abcde" "bcde"
2 "abcde" "acde"
3 "a != b" "a = b"
4 "+-*/" "+-*"
5 "1234.5" "12345"
4 "314151" "31451"
This is code-golf, so shortest answer in bytes wins.
9No one else answer, C# is winning... too late :( – TheLethalCoder – 2017-05-19T13:55:11.740
Can we assume that the char at that idx appears only once? – programmer5000 – 2017-05-19T13:59:54.503
1@programmer5000 Last test case
3
,314151
->31451
. I'd assume not. – TheLethalCoder – 2017-05-19T14:01:12.037@programmer5000 No. See the last test case. – ETHproductions – 2017-05-19T14:01:33.900
Can we take n as a character code? Or must it be in decimal? (for languages like brainfuck, brain-flak, etc.) – James – 2017-05-19T16:46:46.797
@DJMcMayhem I think char-code input would be fine. – ETHproductions – 2017-05-19T17:09:08.813
2Maybe a leaderboard would be helpful, there are plenty of answers to search through already. – Mr. Xcoder – 2017-05-20T04:26:09.957
Are we allowed to modify string
s
in place, or do I have to actually return a new string? – 12Me21 – 2017-05-20T18:56:11.290@12Me21 I believe there was a meta post about this and the general consensus was that functions can modify their arguments in place. So if e.g.
var s="string"; f(s,2); print(s);
prints the proper result, then yes. – ETHproductions – 2017-05-20T19:22:43.853