-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoboScript#1.js
More file actions
22 lines (20 loc) · 1.17 KB
/
RoboScript#1.js
File metadata and controls
22 lines (20 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function highlight(code) {
return code.match(/(F+|R+|L+|[0-9]+)|[()]+/g).reduce((s1, s2) => {
switch (true) {
case /F+/.test(s2):
return s1 + `<span style="color: pink">${s2}</span>`;
case /L+/.test(s2):
return s1 + `<span style="color: red">${s2}</span>`;
case /R+/.test(s2):
return s1 + `<span style="color: green">${s2}</span>`;
case /[0-9]+/.test(s2):
return s1 + `<span style="color: orange">${s2}</span>`;
default:
return s1 + s2;
}
}, "");
}
console.log(highlight("F3RF5LF7"));
console.log(highlight("FFFR345F2LL"));
// '<span style="color: green">RRRRR</span>(<span style="color: pink">F</span><span style="color: orange">45</span><span style="color: red">L</span><span style="color: orange">3</span>)<span style="color: pink">F</span><span style="color: orange">2</span>',
// '<span style="color: green">RRRRR</span><span style="color: pink">F</span><span style="color: orange">45</span><span style="color: red">L</span><span style="color: orange">3</span><span style="color: pink">F</span><span style="color: orange">2</span>'