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.119 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.118 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.117 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.116 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.115 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.114 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.113 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.111 tracks/javascript/exercises/secret-handshake/example.js