remove extraneous spaces between ++/+/--/-#1488
remove extraneous spaces between ++/+/--/-#1488alexlamsl wants to merge 1 commit intomishoo:masterfrom
Conversation
9f84115 to
fd6c2cc
Compare
|
Here's a page that will generate a table of shortest expressions that would work in a given web browser: <html>
<body>
<table>
<tr><th colspan=5>Input</th><th> </th><th>Best</th></tr>
<script>
function evaluate(exp) {
try {
return new Function("var a=1,b=2,c=" + exp + ";return{a:a,b:b,c:c}")();
} catch (e) {
return false;
}
}
function test(expected, exp) {
var actual = evaluate(exp);
if (actual.a === expected.a && actual.b === expected.b && actual.c === expected.c) {
document.write(exp + "</pre></td></tr>");
return true;
}
}
document.write("<pre>");
var P = [
["", "+", "-"],
["++a", "--a", "a", "a--", "a++"],
["+", "-"],
["", "+", "-"],
["++b", "--b", "b", "b--", "b++"]
];
var i = [0, 0, 0, 0, 0], j = 0, p = [];
while (j >= 0) {
if (j == i.length) {
j--;
document.write("<tr><td><pre>" + p.join("</pre></td><td><pre>") + "</pre></td><td> </td><td align=right><pre>");
var e = evaluate(p.join(" "));
var m = [0, 0, 0, 0], n = 0, q = [], f = null;
while (!f && n >= 0) {
if (n == m.length) {
f = q.join("") + p[n--];
if (!test(e, f)) f = null;
} else if (m[n] < 2) {
q[n] = p[n] + (m[n++]++ ? " " : "");
} else {
m[n--] = 0;
}
}
} else if (i[j] < P[j].length) {
p[j] = P[j][i[j++]++];
} else {
i[j--] = 0;
}
}
document.write("</table><p>Test completed.</p>");
</script>
</body>
</html> |
|
I don't know if it's worth the risk for so little reward. See my comment in original ticket: #1377 (comment) |
| [ "a-- + b--", "a--+b--" ], | ||
| [ "a-- + b++", "a--+b++" ], | ||
| [ "a-- - ++b", "a---++b" ], | ||
| [ "a-- - --b", "a--- --b" ], |
There was a problem hiding this comment.
two additional cases:
a-- - - --b;
a++ + + ++b;
|
Any slowdown detected in |
|
@kzc I'm aware of how rare this pattern naturally occurring in the wild. Just thought I'd have some fun with this anyway because:
Thanks for pointing out the missing combinations - I'll update the tests accordingly.
Except for |
691076c to
4e1af6b
Compare
|
LGTM |
4e1af6b to
0a3d52c
Compare
0a3d52c to
6f7e83d
Compare
|
I see that writing tests can take 10 times as much time as the fix itself. :-) |
FIFY 😉 |
fixes #1377
I used the following to test on IE8, which is a modified version of the new test included in this PR: