made with requirebin
Last active
October 22, 2015 21:56
-
-
Save markdalgleish/b566dbe0da72928e1df9 to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var balance = require('balance-parens'); | |
const inputs = [ | |
')()(()(', | |
')))', | |
'()(())()', | |
')()()(()(()))))(', | |
')))())()))(' | |
]; | |
const expected = [ | |
'()()(()())', | |
'((()))', | |
'()(())()', | |
'((()()()(()(()))))()', | |
'(((((()))())()))()' | |
]; | |
const results = inputs.map(balance); | |
const isSuccess = !results | |
.map(function(result, i) { return result === expected[i] }) | |
.some(function(x) { return !x }); | |
document.write('Success: ' + isSuccess); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){(function(global){var baseToString=require("lodash._basetostring");var nativeFloor=Math.floor,nativeIsFinite=global.isFinite;function repeat(string,n){var result="";string=baseToString(string);n=+n;if(n<1||!string||!nativeIsFinite(n)){return result}do{if(n%2){result+=string}n=nativeFloor(n/2);string+=string}while(n);return result}module.exports=repeat}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"lodash._basetostring":2}],2:[function(require,module,exports){function baseToString(value){return value==null?"":value+""}module.exports=baseToString},{}],"balance-parens":[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}var _lodashRepeat=require("lodash.repeat");var _lodashRepeat2=_interopRequireDefault(_lodashRepeat);var reducer=function reducer(state,char){if(state===undefined)state={value:"",depth:0};var isClosing=char===")";var isCorrected=isClosing&&state.depth<1;return{value:""+(isCorrected?"(":"")+state.value+char,depth:state.depth+(isCorrected?0:isClosing?-1:1)}};exports["default"]=function(string){var result=string.split("").reduce(reducer,undefined);return""+result.value+(0,_lodashRepeat2["default"])(")",result.depth)};module.exports=exports["default"]},{"lodash.repeat":1}]},{},[]);var balance=require("balance-parens");const inputs=[")()(()(",")))","()(())()",")()()(()(()))))(",")))())()))("];const expected=["()()(()())","((()))","()(())()","((()()()(()(()))))()","(((((()))())()))()"];const results=inputs.map(balance);const isSuccess=!results.map(function(result,i){return result===expected[i]}).some(function(x){return!x});document.write("Success: "+isSuccess); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"balance-parens": "1.0.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- contents of this file will be placed inside the <body> --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- contents of this file will be placed inside the <head> --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment