Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const isStringConverted = (s1,s2) =>{
- if(!s1.length&&!s2.length) return true;
- let noSpaces = s2.replace(/\s/g,'');
- if(s1.length!=noSpaces.length) return false;
- return [...s1].every(char=>noSpaces.match(new RegExp(char,'g')).length==1);
- }
- describe("isStringConverted", function() {
- describe("можно ли получить из первой строки вторую", function() {
- let expected = true;
- it("строка конвертируется", function() {
- assert.equal(isStringConverted("clockwise", "owe clicks"), expected);
- });
- expected = false;
- it("строка не конвертируется", function() {
- assert.equal(isStringConverted("clockwise", "clockwork"), expected);
- });
- });
- it("при пустом вводе результат true", function() {
- assert.equal(isStringConverted("",""),true);
- });
- it("Разный регистр букв", function() {
- assert.equal(isStringConverted("ClOckwise", "Owe Clicks"),true);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement