Skip to content

Instantly share code, notes, and snippets.

@markdalgleish
Last active October 22, 2015 21:56
Show Gist options
  • Save markdalgleish/b566dbe0da72928e1df9 to your computer and use it in GitHub Desktop.
Save markdalgleish/b566dbe0da72928e1df9 to your computer and use it in GitHub Desktop.

Revisions

  1. markdalgleish revised this gist Oct 22, 2015. No changes.
  2. markdalgleish revised this gist Oct 22, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ const expected = [
    const results = inputs.map(balance);

    const isSuccess = !results
    .map(function(result, i) { return result === expected[i] })
    .some(function(x) { return !x });
    .map(function(result, i) { return result === expected[i] })
    .some(function(x) { return !x });

    document.write('Success: ' + isSuccess);
  3. markdalgleish created this gist Oct 22, 2015.
    26 changes: 26 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    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);
    1 change: 1 addition & 0 deletions minified.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    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);
    7 changes: 7 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    {
    "name": "requirebin-sketch",
    "version": "1.0.0",
    "dependencies": {
    "balance-parens": "1.0.0"
    }
    }
    1 change: 1 addition & 0 deletions page-body.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <!-- contents of this file will be placed inside the <body> -->
    1 change: 1 addition & 0 deletions page-head.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <!-- contents of this file will be placed inside the <head> -->
    1 change: 1 addition & 0 deletions requirebin.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    made with [requirebin](http://requirebin.com)