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.139 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.138 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.137 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.136 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.135 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.134 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.133 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.132 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.131 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.130 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.129 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.128 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.127 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.126 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.125 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.124 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.123 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.122 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.121 tracks/javascript/exercises/secret-handshake/example.js
trackler-2.2.1.120 tracks/javascript/exercises/secret-handshake/example.js