Sha256: 6032610737ae001c42871162263bb1d04dbd5a7e68a139ededb95856483d7c41

Contents?: true

Size: 911 Bytes

Versions: 73

Compression:

Stored size: 911 Bytes

Contents

'use strict';

var bracketPush = module.exports = function (input) {
  if (input.length === 0) {
    return true;
  }

  var bracketArray;
  bracketArray = input;
  var iArr = [];

  if (typeof input === 'string') {
    bracketArray = input.split('');
  }

  var openArray = ['{', '[', '('];
  var closeArray = ['}', ']', ')'];

  for (var i = 0; i < bracketArray.length; i++) {
    for (var j = 0; j < openArray.length; j++) {
      if (bracketArray[i] === openArray[j]) {
        iArr.push(i);
      }
    }
  }

  var topNumber = Math.max.apply(Math, iArr);

  for (var k = 0; k < 3; k++) {
    if (bracketArray[topNumber] === openArray[k]) {
      if (typeof bracketArray[(topNumber + 1)] !== 'undefined') {
        if (bracketArray[(topNumber + 1)] === closeArray[k]) {
          bracketArray.splice(topNumber, 2);
          return bracketPush(bracketArray);
        }
      }
    }
  }
  return false;
};

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.179 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.178 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.177 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.176 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.175 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.174 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.173 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.172 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.171 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.170 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.169 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.167 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.166 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.165 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.164 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.163 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.162 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.161 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.160 tracks/javascript/exercises/bracket-push/example.js