m=x=>['codewarz','abracadabra!'][+x];
const magick_message = x => ['codewarz', 'abracadabra!'][+x];- m=x=>['codewarz','abracadabra!'][+x];
const Test = require('@codewars/test-compat'); describe('Example', function() { it('test case', function() { Test.assertEquals(m(true), 'abracadabra!') Test.assertEquals(m(false), 'codewarz') }); });
- const Test = require('@codewars/test-compat');
- describe('Example', function() {
- it('test case', function() {
Test.assertEquals(magick_message(true), 'abracadabra!')Test.assertEquals(magick_message(false), 'codewarz')- Test.assertEquals(m(true), 'abracadabra!')
- Test.assertEquals(m(false), 'codewarz')
- });
- });
const areAnagrams = (word1, word2) => {
const clean = str => str.replace(/\s/g, '').toLowerCase();
const count = str => Array.from(clean(str)).reduce((map, char) => map.set(char, (map.get(char) || 0) + 1), new Map());
const map1 = count(word1);
const map2 = count(word2);
return Array.from(map1.keys()).every(char => map1.get(char) === map2.get(char));
};
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
const Test = require('@codewars/test-compat');
// 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("Anagram Detector", function () {
it("should return true for anagrams", function () {
Test.assertEquals(areAnagrams("listen", "silent"), true);
Test.assertEquals(areAnagrams("Dormitory", "dirty room"), true);
Test.assertEquals(areAnagrams("The Morse Code", "Here come dots"), true);
Test.assertEquals(areAnagrams("Astronomer", "Moon starer"), true);
});
it("should return false for non-anagrams", function () {
Test.assertEquals(areAnagrams("hello", "world"), false);
Test.assertEquals(areAnagrams("abc", "def"), false);
});
it("should handle spaces and case insensitivity", function () {
Test.assertEquals(areAnagrams("Astronomer", "moon starer"), true);
});
});
Fundamentals
Strings
Fundamentals
Strings
there's a shorter way, but same steps as my previous kumite.
Fundamentals
Strings
transform array to string by .split("")
, reverse it then make it string again by .join("")