Sha256: 2cbdb780e8e3121c66b01d2bdcc9669cf4fe544114dee1635ce56cf954c05a2d

Contents?: true

Size: 921 Bytes

Versions: 68

Compression:

Stored size: 921 Bytes

Contents

'use strict';

function SecretHandshake(handshake) {
  SecretHandshake.allCommands = [ 'wink', 'double blink', 'close your eyes', 'jump', 'REVERSE' ];
  var handshakeCommands = SecretHandshake.allCommands;

  if (typeof handshake !== 'number') {
    throw new Error('Handshake must be a number');
  }

  this.commands = function () {
    return this.shakeWith;
  };

  this.calculateHandshake = function () {
    var shakeWith = [];

    for (var i = 0; i < handshakeCommands.length; i++) {
      var currentCommand = handshakeCommands[i];
      var handshakeHasCommand = (handshake & Math.pow(2, i));

      if (handshakeHasCommand) {
        if (currentCommand === 'REVERSE') {
          shakeWith.reverse();
        } else {
          shakeWith.push(handshakeCommands[i]);
        }
      }
    }

    return shakeWith;
  };

  this.shakeWith = this.calculateHandshake(handshake);
}

module.exports = SecretHandshake;

Version data entries

68 entries across 68 versions & 1 rubygems

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