-
Notifications
You must be signed in to change notification settings - Fork 0
/
deadfish.js
46 lines (39 loc) · 889 Bytes
/
deadfish.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Return the output array, and ignore all non-op characters
function parse( data ) {
deadFish.n = 0;
deadFish.result = [];
for (let letter of data) {
if (deadFish[letter]) {
deadFish[letter]()
}
}
return deadFish.result
}
const deadFish = {
n: 0,
result: [],
i: () => deadFish.n++,
d: () => deadFish.n--,
s: () => deadFish.n = deadFish.n * deadFish.n,
o: () => deadFish.result.push(deadFish.n)
};
/*
Parameters:
a string, where each character represents an instruction
Return Value:
an array, consisting of values computed by the deadfish
Example:
parse("iiisdoso")
increments i up to 3,
squares i, making it 9,
decrements i to 8,
outputs i to the array
squares i to 64
outputs it to the array
Psuedocode:
just have make a deadfish object, with:
an i field,
a result field,
an increment / decrement method,
and an output to array method
*/