shorter and faster
function pinValidator(pin){ if (![4,6].includes(pin.length)) return false if (pin.match(/^\d+$/)) return true return false }
function pinValidator(pin) {var pinLength = pin.length;var pinIsCorrect = (pinLength === 4 || pinLength === 6);var onlyNumbers = pin.match (/^\d+$/);if (pinIsCorrect && onlyNumbers){return true;console.log("TRUE");}else {return false;console.log("FALSE");}};pinValidator('88888');- function pinValidator(pin){
- if (![4,6].includes(pin.length)) return false
- if (pin.match(/^\d+$/)) return true
- return false
- }
describe("Solution for PIN Validator", function() { it("should test for validity", function() { Test.assertEquals(pinValidator('888'),false); Test.assertEquals(pinValidator('8888'),true); Test.assertEquals(pinValidator('88888'),false); Test.assertEquals(pinValidator('888Abc'),false); Test.assertEquals(pinValidator('a888'),false); }); });
// TODO: Add your tests here// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)// are still available for now.//// For new tests, using [Chai](https://chaijs.com/) is recommended.// You can use it by requiring:// const assert = require("chai").assert;// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.describe("Solution", function() {it("should test for something", function() {// Test.assertEquals(1 + 1, 2);// assert.strictEqual(1 + 1, 2);});});- describe("Solution for PIN Validator", function() {
- it("should test for validity", function() {
- Test.assertEquals(pinValidator('888'),false);
- Test.assertEquals(pinValidator('8888'),true);
- Test.assertEquals(pinValidator('88888'),false);
- Test.assertEquals(pinValidator('888Abc'),false);
- Test.assertEquals(pinValidator('a888'),false);
- });
- });