/** The output of this kata is the number you need to create the metal sign with your fingers, using these rules: - You start with all fingers "up" - You count from your thumb - You put the finger where you end down - You start again with your thumb (or the next finger which is up) - If your number is not yet reached and you are out of fingers you count on with the "left" side - The Metal Sign is Thumb down, Index up, Middle down, Ring down, Pinky up - Have fun :-) - If you are really fast you can also try with the "Double Metal" (Same with 10 Fingers) **/ // Parallell programmed / quick draft with ChatGPT - non-functional yet ^^ function createMetalSign(number) { const fingers = [1, 1, 1, 1, 1]; // Initialize all fingers "up" let currentFinger = 0; // Start counting from the thumb (index 0) while (number > 0) { if (fingers[currentFinger] === 1) { // If the finger is up, put it down fingers[currentFinger] = 0; number--; } // Move to the next finger currentFinger = (currentFinger + 1) % 5; } console.log(fingers) return fingers; }
- /**
- The output of this kata is the number you need to create the metal sign
- with your fingers, using these rules:
- - You start with all fingers "up"
- - You count from your thumb
- - You put the finger where you end down
- - You start again with your thumb (or the next finger which is up)
- - If your number is not yet reached and you are out of fingers you count on with the "left" side
- - The Metal Sign is Thumb down, Index up, Middle down, Ring down, Pinky up
- - Have fun :-)
- - If you are really fast you can also try with the "Double Metal" (Same with 10 Fingers)
- **/
function calculate(){console.log(0);}- // Parallell programmed / quick draft with ChatGPT - non-functional yet ^^
- function createMetalSign(number) {
- const fingers = [1, 1, 1, 1, 1]; // Initialize all fingers "up"
- let currentFinger = 0; // Start counting from the thumb (index 0)
- while (number > 0) {
- if (fingers[currentFinger] === 1) {
- // If the finger is up, put it down
- fingers[currentFinger] = 0;
- number--;
- }
- // Move to the next finger
- currentFinger = (currentFinger + 1) % 5;
- }
- console.log(fingers)
- return fingers;
- }
// Parallell programmed / quick draft with ChatGPT - non-functional yet ^^ // 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("createMetalSign tests", function() { it("should return Metal Sign for the correct number", function() { // Get the number required to create the Metal Sign const metalSignNumber = findNumberForMetalSign(); const result = createMetalSign(metalSignNumber); assert.deepEqual(result, [0, 1, 0, 0, 1], "Expected Metal Sign"); }); });
- // Parallell programmed / quick draft with ChatGPT - non-functional yet ^^
- // 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 test for something", function() {calculate();// Test.assertEquals(1 + 1, 2);// assert.strictEqual(1 + 1, 2);- describe("createMetalSign tests", function() {
- it("should return Metal Sign for the correct number", function() {
- // Get the number required to create the Metal Sign
- const metalSignNumber = findNumberForMetalSign();
- const result = createMetalSign(metalSignNumber);
- assert.deepEqual(result, [0, 1, 0, 0, 1], "Expected Metal Sign");
- });