function dumbRockPaperScissors(player1, player2) { let condition = { Scissors: "Paper", Rock: "Scissors", Paper: "Rock", }; switch (true) { case player2 === condition[player1]: return "Player 1 wins"; case player1 === condition[player2]: return "Player 2 wins"; case player1 === player2: return "Draw"; } }
- function dumbRockPaperScissors(player1, player2) {
let condition = {Scissors: 'Paper',Rock: 'Scissors',Paper: 'Rock',}if (player2 === condition[player1]) {return "Player 1 wins";}if (player1 === condition[player2]) {return "Player 2 wins";}if (player1 === player2) {return "Draw";- let condition = {
- Scissors: "Paper",
- Rock: "Scissors",
- Paper: "Rock",
- };
- switch (true) {
- case player2 === condition[player1]: return "Player 1 wins";
- case player1 === condition[player2]: return "Player 2 wins";
- case player1 === player2: return "Draw";
- }
- }
Strings
Create a function that takes a string and returns true if no character appears twice, false otherwise.
function isUnique(string) {
let knownChars = "";
for (let char of string) {
if (!knownChars.includes(char)) {
knownChars += char;
} else {
return false;
}
}
return true;
}
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should return true for strings without repetition", function() {
Test.assertEquals(isUnique('gino'), true);
Test.assertEquals(isUnique('glhf'), true);
// assert.strictEqual(1 + 1, 2);
});
it("should return false for strings with repetition", function() {
Test.assertEquals(isUnique('gg'), false);
Test.assertEquals(isUnique('phillip'), false);
// assert.strictEqual(1 + 1, 2);
});
});