Built with blockbuilder.org
forked from anonymous's block: fresh block
forked from anonymous's block: balance checker
Built with blockbuilder.org
forked from anonymous's block: fresh block
forked from anonymous's block: balance checker
| <!DOCTYPE html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
| <style> | |
| body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
| svg { width:100%; height: 100% } | |
| </style> | |
| </head> | |
| <body> | |
| <script> | |
| // Feel free to change or delete any of the code you see! | |
| var inputs = ['{}()[]', '{(})']; | |
| function check(v) { | |
| var scores = {} | |
| , symbols = { | |
| 'square': ['[', ']'] | |
| , 'curly': ['{', '}'] | |
| , 'paren': ['(', ')'] | |
| } | |
| ; | |
| d3.keys(symbols).forEach(function(s) { | |
| scores[s] = v.indexOf(symbols[s][1]) - v.indexOf(symbols[s][0]); | |
| }) | |
| return scores; | |
| } // check() | |
| var res = inputs.map(function(str) { | |
| var blah = check(str); | |
| return d3.values(blah).every(function(v) { return v%2; }) ? "YES" : "NO"; | |
| }); | |
| console.log(res); | |
| return res; | |
| </script> | |
| </body> |