Sometimes in chat, if someone says something you agree with, you'll send a message with an ^
, which points at the message above:
Radvylf: Cats are far superior to JavaScript
You: ^
Sometimes you'll also add some text:
Radvylf: I sure do like integers
You: I mostly agree with ^ but floats are pretty neat too
You can also use multiple ^
s to refer to messages farther back:
Timmy: Puppies are adorable.
Radvylf: I hate puppies.
You: ^^
In this challenge, given a chat log with ^
s, you'll replace the ^
s with the messages they refer to.
Task:
Given a multiline string of messages (without usernames), or an array where each message is a string (or some representation of one), resolve all of the ^
references in it. Note that messages can refer to messages that themselves have ^
s, which need to be properly resolved.
For example:
Cats are funny sometimes
^
^^, but I've met serious cats too.
^^
Opinions on static typing?
It's okay.
^ It depends on the implementation, though.
^ Big difference between good and bad static ty
^ping
Thanks ^_^
This would become:
Cats are funny sometimes
Cats are funny sometimes
Cats are funny sometimes, but I've met serious cats too.
Cats are funny sometimes
Opinions on static typing?
It's okay.
It's okay. It depends a lot on the implementation, though.
It's okay. It depends a lot on the implementation, though. Big difference between good and bad static ty
It's okay. It depends a lot on the implementation, though. Big difference between good and bad static typing
Thanks It's okay. It depends a lot on the implementation, though. Big difference between good and bad static typing_It's okay. It depends a lot on the implementation, though. Big difference between good and bad static typing
You'll never need to resolve a group of ^
s that points up more times than there are messages to point at. E.g., ^
will never be the first line, and ^^
will never be the second.
Test cases:
Input:
a
Output:
a
Input:
a
^b
^^
Output:
a
ab
a
Input:
a
^b
^c
^ ^^ ^^^
Output:
a
ab
abc
abc ab a
Other:
This is code-golf, so shortest answer in bytes per language wins.