Strings
const isUnique = (string) => { const chars = [...new Intl.Segmenter().segment(string)].map(x => x.segment) return new Set(chars).size === chars.length }
const isUnique = string => new Set(string).size === string.length- const isUnique = (string) => {
- const chars = [...new Intl.Segmenter().segment(string)].map(x => x.segment)
- return new Set(chars).size === chars.length
- }
// 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); Test.assertEquals(isUnique('π¨βπ¨βπ§βπ§'), true); Test.assertEquals(isUnique('π¨βπ¨βπ§βπ§π¨'), true); }); it("should return false for strings with repetition", function() { Test.assertEquals(isUnique('gg'), false); Test.assertEquals(isUnique('phillip'), false); Test.assertEquals(isUnique('π¨π§βπ§βπ§βπ§π¨'), false); }); });
- // 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);- Test.assertEquals(isUnique('π¨βπ¨βπ§βπ§'), true);
- Test.assertEquals(isUnique('π¨βπ¨βπ§βπ§π¨'), true);
- });
- it("should return false for strings with repetition", function() {
- Test.assertEquals(isUnique('gg'), false);
- Test.assertEquals(isUnique('phillip'), false);
// assert.strictEqual(1 + 1, 2);});- Test.assertEquals(isUnique('π¨π§βπ§βπ§βπ§π¨'), false);
- });
- });