| Bytes | Lang | Time | Link |
|---|---|---|---|
| 005 | Vyxal 3 | 241105T103423Z | Themooni |
| 068 | Janet | 250321T152215Z | xigoi |
| 058 | APL | 241108T172821Z | Aaron |
| 049 | JavaScript | 241105T151910Z | Shaggy |
| 011 | Japt | 241105T102453Z | Shaggy |
| 053 | JavaScript Node.js | 241105T062210Z | l4m2 |
| 081 | jq | 241105T034237Z | Fragment |
| 081 | R | 231010T080102Z | Dominic |
| 099 | Java 10 | 231004T100303Z | Kevin Cr |
| 061 | Perl 5 lp | 231004T081337Z | Nahuel F |
| 085 | Haskell | 231005T005832Z | tzlil |
| 121 | Go | 231004T210546Z | bigyihsu |
| 005 | 05AB1E | 231004T034156Z | Command |
| 006 | Jelly | 231004T164501Z | Unrelate |
| 095 | R | 231004T122633Z | pajonk |
| 059 | Python | 231004T085223Z | mousetai |
| 045 | Retina 0.8.2 | 231004T085258Z | Neil |
| 016 | Charcoal | 231004T083822Z | Neil |
| 041 | Ruby | 231004T072541Z | G B |
| 007 | Husk | 231004T034312Z | Leo |
| 074 | PowerShell Core | 231004T020558Z | Julian |
Vyxal 3, 5 bytes
-6 bytes: i was working around online interpreter bugs that are now fixed
(nsƵj
(nsƵj
(n # for each char in key
s # split string by that char
Ƶ # get the last element
j # join by that
💎
Created with the help of Luminespire.
<script type="vyxal3">
(nsƵj
</script>
<script>
args=[["|","a|b|c|hello"],["|","He||o, wor|d!|l"],["|&","| | & &&|house|green"],["}~","N~give}up,n~let}down~ever gonna } you "],["|}~","How much } w|a }~~if a }~c|~}?~chuck }wood|ould "],["~","She sells~ells by the~ore~ sea sh"]]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>
Janet, 68 bytes
|(reduce|(let[s(string/split $1 $)](string/join s(array/pop s)));$&)
Takes a string and a tuple/array of characters.
APL, 58 chars
{⊃{(⊃⌽t){⊃⍺{⍺,⍺⍺,⍵}/⍵}¯1↓t←⍵{⍵{⍵/⍨⍺≠⍵}¨⍺⊂⍨1,⍺=⍵}⍺}/⌽⍵,⍨⊂⍺}
Splitting into helper functions to clarify:
join←{⊃⍺{⍺,⍺⍺,⍵}/⍵}
{⍺,⍺⍺,⍵} ⍝ Concatenate the left arg, the left operand arg, and the right arg
/⍵ ⍝ Run this over the left arg: an array of elements to join
⍺ ⍝ Pass the left arg as the inner functions operand: the element to add between the right arg
⊃ ⍝ Disclose to return a simple array
split←{⍵{⍵/⍨⍺≠⍵}¨⍺⊂⍨1,⍺=⍵}
⍺=⍵ ⍝ Find where elements of the input string (left) are equal to the delimiter (right)
1, ⍝ Tack a 1 on the front to "start" the first partition
⍺⊂⍨ ⍝ Partition the input string based on the generated mask
{ }¨ ⍝ For each of those partitions:
⍺≠⍵ ⍝ Find where the string does not match the delimiter
⍵/⍨ ⍝ and just grab those elements (remove the delimiter)
decode←{(⊃⌽t)join ¯1↓t←⍵ split ⍺} ⍝ Decode a single iteration
t←⍵ split ⍺ ⍝ Split the input string by the delimiter and store in t
¯1↓ ⍝ Take all but the last element
join ⍝ and join it
( ) ⍝ with the first element
⊃⌽t ⍝ reverse the list and take the first element
{⊃decode/⌽⍵,⍨⊂⍺} ⍝ Take the input string on the left and the list of decode chars on the right
⍵,⍨⊂⍺ ⍝ Enclose the string and tack on the decode chars to make one list
⌽ ⍝ Reverse it so it starts with the input string and then has the decode chars in the order they need to be processed
decode/ ⍝ Run decode over this array
⍝ The first and second elements of will be the input string and the first decode char; once that runs, the result is the partially decoded input and the next decode char, etc until complete
⊃ ⍝ Disclose to return a simple array
JavaScript, 49 bytes
Takes the delimiters as an array of characters.
s=>d=>d.map(c=>s=(a=s.split(c)).join(a.pop()))&&s
jq, 81 bytes
. as$x|($x[1]|split(""))|reduce.[]as$c($x[0];split($c)|.[-1]as$n|.[:-1]|join($n))
De-minified:
. as $input
| ($input[1] | split(""))
| reduce .[] as $char (
$input[0];
split($char) | .[-1] as $last | .[:-1] | join($last)
)
I'm sure this can be improved on since I feel like it overuses variables, but it was fun to write!
R, 81 bytes
\(x,y)Reduce(\(x,y)paste(head(a<-el(strsplit(x,y,T)),-1),collapse=tail(a,1)),y,x)
Port of unrelated string's Jelly answer.
Java 10, 121 101 99 bytes
a->s->{int i;for(var c:a)s=s.substring(0,i=s.lastIndexOf(c)).replace(c,s.substring(i+1));return s;}
-17 bytes (and an additional -3 implicit) thanks to @NahuelFouilleul by using substrings instead of split to an array.
-2 bytes thanks to @ceilingcat.
Explanation:
a->s->{ // Method with String-array & String parameters and String return
int i; // Index-integer `i`, starting uninitialized
for(var c:a) // Loop over the input-characters:
s= // Overwrite String `s` with:
s.substring(0,i=s.lastIndexOf(c))
// A substring until (excluding) the last occurrence of the
// current character (and also set `i` to this last index
// of the character at the same time)
.replace(c, // From which the current character is replaced with
s.substring(i+1));// the trailing substring after index `i`
return s;} // Return the modified `s` as result-String
Perl 5 -lp, 64, 61 bytes
s/(\S+) //;for$c($1=~/./g){@a=split/\Q$c/;$_=join pop(@a),@a}
Another using regex
Perl 5 -lp, 64, 54 bytes
s/^(\S)(?|.*\K\1(?=.*\1(.*)$)|(.*)\1.*)/$2/&&redo;s; ;
Haskell, 89 85 bytes
f=foldl(\s c->(\(a,b)->reverse$tail b>>=(\x->last$[x]:[a|x==c])).span(c/=)$reverse s)
Go, 121 bytes
import."strings"
type S=string
func f(s,c S)S{for _,r:=range c{L:=Split(s,S(r))
l:=len(L)-1
s=Join(L[:l],L[l])}
return s}
05AB1E, 6 5 bytes
-1 thanks to @KevinCruijssen
vy¡`ý
Explanation
v # for each char in the char list
y # push it
¡ # split the current string by it
` # dump the parts to stack
ý # join the stack by the last part
Jelly, 6 bytes
ṣjṪ$¥ƒ
Takes the delimiters on the left and the compressed string on the right.
¥ƒ Reduce the delimiters by, starting with the compressed string:
ṣ Split on the delimiter
j and join that on
Ṫ$ its last element (removed).
R, 95 bytes
f=\(s,L,`?`=length,x=el(strsplit(s,L[1],T)),t=?x)`if`(?L,f(paste(x[-t],collapse=x[t]),L[-1]),s)
Retina 0.8.2, 45 bytes
+`(?=.*¶(.))\1((?=.*\1(.+))|.+)|(?<=¶).|¶$
$3
Try it online! No test suite because I can't think of a good separator between the two strings. Explanation:
+`
Repeat for each character in the list.
(?=.*¶(.))\1((?=.*\1(.+))|.+)|(?<=¶).|¶$
$3
Search the string for occurrences of the first character in the list, and try to replace it with the word after the last occurrence, otherwise delete the last occurrence and the word after it. Finish by deleting the character from the list and the list itself once the last character has been processed.
Charcoal, 16 bytes
Fη«≔⪪θιυ≔⪫υ⊟υθ»θ
Try it online! Link is to verbose version of code. Explanation: Charcoal doesn't have a good way to refer to the split string twice, so it costs a block and an assignment.
Fη«
Loop over the list of characters.
≔⪪θιυ
Split the string.
≔⪫υ⊟υθ
Join it on the popped element.
»θ
Output the final result.
Husk, 7 bytes
F(↔ΓJx↔
Explanation
F(↔ΓJx↔
F For each character in the character list:
↔ flip the string
x split it on the given character
ΓJ use the first element to join the rest of the list
↔ flip the string back
Why all that flipping back and forth? Because in Husk it's often easier to operate on the first element of a list than the last (Γ here does exactly that). We could manually take the last element and everything except that, but the program would have the same length: F(§J→hx
We could solve the challenge in 5 bytes (F(ΓJx) if we were allowed to operate on the reversed string, or to have the changes listed at the beginning of the string.
PowerShell Core, 74 bytes
param($t)$args|%{$j=($o=$t|% S*t $_)[-1]
$t=$o[0..($o.Count-2)]-join$j}
$t
Or using $ofs