Sha256: bc676b5ebe258cec8aa4962d424581c8674d127b11a00a38b807385c44cf60a1

Contents?: true

Size: 908 Bytes

Versions: 255

Compression:

Stored size: 908 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

255 entries across 255 versions & 1 rubygems

Version Path
trackler-2.2.1.37 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.36 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.35 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.34 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.33 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.32 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.31 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.30 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.29 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.28 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.27 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.26 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.25 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.24 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.23 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.22 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.21 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.20 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.19 tracks/javascript/exercises/bracket-push/example.js
trackler-2.2.1.18 tracks/javascript/exercises/bracket-push/example.js