Write a function to implement a Brain**** interpreter. The function will take a string as a parameter and should return a string as the output. More details are given below :
RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages.
Below are links to each of the versions of RCBF.
An implementation need only properly implement the following instructions:
{|
!Command
!Description
|-
| style="text-align:center"| >
|| Move the pointer to the right
|-
| style="text-align:center"| <
|| Move the pointer to the left
|-
| style="text-align:center"| +
|| Increment the memory cell under the pointer
|-
| style="text-align:center"| -
|| Decrement the memory cell under the pointer
|-
| style="text-align:center"| .
|| Output the character signified by the cell at the pointer
|-
| style="text-align:center"| ,
|| Input a character and store it in the cell at the pointer
|-
| style="text-align:center"| [
|| Jump past the matching ]
if the cell under the pointer is 0
|-
| style="text-align:center"| ]
|| Jump back to the matching [
if the cell under the pointer is nonzero
|}
Any cell size is allowed, EOF (End-O-File) support is optional, as is whether you have bounded or unbounded memory.
brain(bye)
should retuen a string
testString: 'assert(typeof brain(bye) === "string", "brain(bye)
should return a string");'
- text: 'brain("++++++[>++++++++++<-]>+++++.")
++++++++++<-]>+++++."),"A", "brain("++++++[>++++++++++<-]>+++++.")
brain(bye) should return Goodbye, World!\\r\\n
'
testString: 'assert.equal(brain(bye), "Goodbye, World!\r\n", "brain(bye)
should return Goodbye, World!\\r\\n
");'
- text: brain(hello)
should return Hello World!\\n
'
testString: 'assert.equal(brain(hello), "Hello World!\n", "brain(hello)
should return Hello World!\\n
");'
- text: 'brain(fib)
should return 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89
'
testString: 'assert.equal(brain(fib), "1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89", "brain(fib)
should return 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89
");'
```