From 86b4ec936aebf312d2764d72f571fdbe29ac0f7d Mon Sep 17 00:00:00 2001 From: Cool-Katt Date: Wed, 15 Jan 2025 14:22:07 +0200 Subject: [PATCH 1/4] Update anagram.spec.js --- exercises/practice/anagram/anagram.spec.js | 105 ++++++++++++++------- 1 file changed, 73 insertions(+), 32 deletions(-) diff --git a/exercises/practice/anagram/anagram.spec.js b/exercises/practice/anagram/anagram.spec.js index f84b604dab..10f5a6af41 100644 --- a/exercises/practice/anagram/anagram.spec.js +++ b/exercises/practice/anagram/anagram.spec.js @@ -1,84 +1,125 @@ import { describe, expect, test, xtest } from '@jest/globals'; import { findAnagrams } from './anagram'; +let areSetsEqual = (setA, setB) => setA.size === setB.size && [...setA].every(val => setB.has(val)); + describe('Anagram', () => { test('no matches', () => { + let expected = []; + let actual = findAnagrams('diaper', ['hello', 'world', 'zombies', 'pants']); expect( - findAnagrams('diaper', ['hello', 'world', 'zombies', 'pants']), - ).toEqual([]); + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); xtest('detects two anagrams', () => { - expect(findAnagrams('solemn', ['lemons', 'cherry', 'melons'])).toEqual([ - 'lemons', - 'melons', - ]); + let expected = ['lemons', 'melons']; + let actual = findAnagrams('solemn', ['lemons', 'cherry', 'melons']); + expect( + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); xtest('does not detect anagram subsets', () => { - expect(findAnagrams('good', ['dog', 'goody'])).toEqual([]); + let expected = []; + let actual = findAnagrams('good', ['dog', 'goody']); + expect( + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); xtest('detects anagram', () => { + let expected = ['inlets']; + let actual = findAnagrams('listen', ['enlists', 'google', 'inlets', 'banana']); expect( - findAnagrams('listen', ['enlists', 'google', 'inlets', 'banana']), - ).toEqual(['inlets']); + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); xtest('detects three anagrams', () => { + let expected = ['gallery', 'regally', 'largely']; + let actual = findAnagrams('allergy', [ + 'gallery', + 'ballerina', + 'regally', + 'clergy', + 'largely', + 'leading' + ]); expect( - findAnagrams('allergy', [ - 'gallery', - 'ballerina', - 'regally', - 'clergy', - 'largely', - 'leading', - ]), - ).toEqual(['gallery', 'regally', 'largely']); + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); xtest('detects multiple anagrams with different case', () => { - expect(findAnagrams('nose', ['Eons', 'ONES'])).toEqual(['Eons', 'ONES']); + let expected = ['Eons', 'ONES']; + let actual = findAnagrams('nose', ['Eons', 'ONES']); + expect( + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); xtest('does not detect non-anagrams with identical checksum', () => { - expect(findAnagrams('mass', ['last'])).toEqual([]); + let expected = []; + let actual = findAnagrams('mass', ['last']); + expect( + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); xtest('detects anagrams case-insensitively', () => { + let expected = ['Carthorse']; + let actual = findAnagrams('Orchestra', ['cashregister', 'Carthorse', 'radishes']); expect( - findAnagrams('Orchestra', ['cashregister', 'Carthorse', 'radishes']), - ).toEqual(['Carthorse']); + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); xtest('detects anagrams using case-insensitive subject', () => { + let expected = ['carthorse']; + let actual = findAnagrams('Orchestra', ['cashregister', 'carthorse', 'radishes']); expect( - findAnagrams('Orchestra', ['cashregister', 'carthorse', 'radishes']), - ).toEqual(['carthorse']); + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); xtest('detects anagrams using case-insensitive possible matches', () => { + let expected = ['Carthorse']; + let actual = findAnagrams('orchestra', ['cashregister', 'Carthorse', 'radishes']); expect( - findAnagrams('orchestra', ['cashregister', 'Carthorse', 'radishes']), - ).toEqual(['Carthorse']); + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); xtest('does not detect an anagram if the original word is repeated', () => { - expect(findAnagrams('go', ['go Go GO'])).toEqual([]); + let expected = []; + let actual = findAnagrams('go', ['go Go GO']); + expect( + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); xtest('anagrams must use all letters exactly once', () => { - expect(findAnagrams('tapper', ['patter'])).toEqual([]); + let expected = []; + let actual = findAnagrams('tapper', ['patter']); + expect( + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); xtest('words are not anagrams of themselves (case-insensitive)', () => { - expect(findAnagrams('BANANA', ['BANANA', 'Banana', 'banana'])).toEqual([]); + let expected = []; + let actual = findAnagrams('BANANA', ['BANANA', 'Banana', 'banana']); + expect( + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); xtest('words other than themselves can be anagrams', () => { - expect(findAnagrams('LISTEN', ['Listen', 'Silent', 'LISTEN'])).toEqual([ - 'Silent', - ]); + let expected = ['Silent']; + let actual = findAnagrams('LISTEN', ['Listen', 'Silent', 'LISTEN']); + expect( + areSetsEqual(new Set(expected), new Set(actual)) + ).toEqual(true); }); }); From bddee6d436984e959160420fc04c7645f3ffda2f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 15 Jan 2025 12:26:57 +0000 Subject: [PATCH 2/4] [CI] Format code --- exercises/practice/anagram/anagram.spec.js | 86 ++++++++++------------ 1 file changed, 38 insertions(+), 48 deletions(-) diff --git a/exercises/practice/anagram/anagram.spec.js b/exercises/practice/anagram/anagram.spec.js index 10f5a6af41..c62ccf2a51 100644 --- a/exercises/practice/anagram/anagram.spec.js +++ b/exercises/practice/anagram/anagram.spec.js @@ -1,39 +1,37 @@ import { describe, expect, test, xtest } from '@jest/globals'; import { findAnagrams } from './anagram'; -let areSetsEqual = (setA, setB) => setA.size === setB.size && [...setA].every(val => setB.has(val)); +let areSetsEqual = (setA, setB) => + setA.size === setB.size && [...setA].every((val) => setB.has(val)); describe('Anagram', () => { test('no matches', () => { let expected = []; let actual = findAnagrams('diaper', ['hello', 'world', 'zombies', 'pants']); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('detects two anagrams', () => { let expected = ['lemons', 'melons']; let actual = findAnagrams('solemn', ['lemons', 'cherry', 'melons']); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('does not detect anagram subsets', () => { let expected = []; let actual = findAnagrams('good', ['dog', 'goody']); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('detects anagram', () => { let expected = ['inlets']; - let actual = findAnagrams('listen', ['enlists', 'google', 'inlets', 'banana']); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + let actual = findAnagrams('listen', [ + 'enlists', + 'google', + 'inlets', + 'banana', + ]); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('detects three anagrams', () => { @@ -44,82 +42,74 @@ describe('Anagram', () => { 'regally', 'clergy', 'largely', - 'leading' + 'leading', ]); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('detects multiple anagrams with different case', () => { let expected = ['Eons', 'ONES']; let actual = findAnagrams('nose', ['Eons', 'ONES']); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('does not detect non-anagrams with identical checksum', () => { let expected = []; let actual = findAnagrams('mass', ['last']); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('detects anagrams case-insensitively', () => { let expected = ['Carthorse']; - let actual = findAnagrams('Orchestra', ['cashregister', 'Carthorse', 'radishes']); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + let actual = findAnagrams('Orchestra', [ + 'cashregister', + 'Carthorse', + 'radishes', + ]); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('detects anagrams using case-insensitive subject', () => { let expected = ['carthorse']; - let actual = findAnagrams('Orchestra', ['cashregister', 'carthorse', 'radishes']); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + let actual = findAnagrams('Orchestra', [ + 'cashregister', + 'carthorse', + 'radishes', + ]); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('detects anagrams using case-insensitive possible matches', () => { let expected = ['Carthorse']; - let actual = findAnagrams('orchestra', ['cashregister', 'Carthorse', 'radishes']); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + let actual = findAnagrams('orchestra', [ + 'cashregister', + 'Carthorse', + 'radishes', + ]); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('does not detect an anagram if the original word is repeated', () => { let expected = []; let actual = findAnagrams('go', ['go Go GO']); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('anagrams must use all letters exactly once', () => { let expected = []; let actual = findAnagrams('tapper', ['patter']); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('words are not anagrams of themselves (case-insensitive)', () => { let expected = []; let actual = findAnagrams('BANANA', ['BANANA', 'Banana', 'banana']); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('words other than themselves can be anagrams', () => { let expected = ['Silent']; let actual = findAnagrams('LISTEN', ['Listen', 'Silent', 'LISTEN']); - expect( - areSetsEqual(new Set(expected), new Set(actual)) - ).toEqual(true); + expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); }); From 173082197eabc6ac68a821b2922596b3866d8b4f Mon Sep 17 00:00:00 2001 From: Cool-Katt Date: Wed, 15 Jan 2025 14:57:18 +0200 Subject: [PATCH 3/4] no reason to use `let` here, i think --- exercises/practice/anagram/anagram.spec.js | 58 +++++++++++----------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/exercises/practice/anagram/anagram.spec.js b/exercises/practice/anagram/anagram.spec.js index c62ccf2a51..7992d2c5f8 100644 --- a/exercises/practice/anagram/anagram.spec.js +++ b/exercises/practice/anagram/anagram.spec.js @@ -1,31 +1,31 @@ import { describe, expect, test, xtest } from '@jest/globals'; import { findAnagrams } from './anagram'; -let areSetsEqual = (setA, setB) => +const areSetsEqual = (setA, setB) => setA.size === setB.size && [...setA].every((val) => setB.has(val)); describe('Anagram', () => { test('no matches', () => { - let expected = []; - let actual = findAnagrams('diaper', ['hello', 'world', 'zombies', 'pants']); + const expected = []; + const actual = findAnagrams('diaper', ['hello', 'world', 'zombies', 'pants']); expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('detects two anagrams', () => { - let expected = ['lemons', 'melons']; - let actual = findAnagrams('solemn', ['lemons', 'cherry', 'melons']); + const expected = ['lemons', 'melons']; + const actual = findAnagrams('solemn', ['lemons', 'cherry', 'melons']); expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('does not detect anagram subsets', () => { - let expected = []; - let actual = findAnagrams('good', ['dog', 'goody']); + const expected = []; + const actual = findAnagrams('good', ['dog', 'goody']); expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('detects anagram', () => { - let expected = ['inlets']; - let actual = findAnagrams('listen', [ + const expected = ['inlets']; + const actual = findAnagrams('listen', [ 'enlists', 'google', 'inlets', @@ -35,8 +35,8 @@ describe('Anagram', () => { }); xtest('detects three anagrams', () => { - let expected = ['gallery', 'regally', 'largely']; - let actual = findAnagrams('allergy', [ + const expected = ['gallery', 'regally', 'largely']; + const actual = findAnagrams('allergy', [ 'gallery', 'ballerina', 'regally', @@ -48,20 +48,20 @@ describe('Anagram', () => { }); xtest('detects multiple anagrams with different case', () => { - let expected = ['Eons', 'ONES']; - let actual = findAnagrams('nose', ['Eons', 'ONES']); + const expected = ['Eons', 'ONES']; + const actual = findAnagrams('nose', ['Eons', 'ONES']); expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('does not detect non-anagrams with identical checksum', () => { - let expected = []; - let actual = findAnagrams('mass', ['last']); + const expected = []; + const actual = findAnagrams('mass', ['last']); expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('detects anagrams case-insensitively', () => { - let expected = ['Carthorse']; - let actual = findAnagrams('Orchestra', [ + const expected = ['Carthorse']; + const actual = findAnagrams('Orchestra', [ 'cashregister', 'Carthorse', 'radishes', @@ -70,8 +70,8 @@ describe('Anagram', () => { }); xtest('detects anagrams using case-insensitive subject', () => { - let expected = ['carthorse']; - let actual = findAnagrams('Orchestra', [ + const expected = ['carthorse']; + const actual = findAnagrams('Orchestra', [ 'cashregister', 'carthorse', 'radishes', @@ -80,8 +80,8 @@ describe('Anagram', () => { }); xtest('detects anagrams using case-insensitive possible matches', () => { - let expected = ['Carthorse']; - let actual = findAnagrams('orchestra', [ + const expected = ['Carthorse']; + const actual = findAnagrams('orchestra', [ 'cashregister', 'Carthorse', 'radishes', @@ -90,26 +90,26 @@ describe('Anagram', () => { }); xtest('does not detect an anagram if the original word is repeated', () => { - let expected = []; - let actual = findAnagrams('go', ['go Go GO']); + const expected = []; + const actual = findAnagrams('go', ['go Go GO']); expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('anagrams must use all letters exactly once', () => { - let expected = []; - let actual = findAnagrams('tapper', ['patter']); + const expected = []; + const actual = findAnagrams('tapper', ['patter']); expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('words are not anagrams of themselves (case-insensitive)', () => { - let expected = []; - let actual = findAnagrams('BANANA', ['BANANA', 'Banana', 'banana']); + const expected = []; + const actual = findAnagrams('BANANA', ['BANANA', 'Banana', 'banana']); expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); xtest('words other than themselves can be anagrams', () => { - let expected = ['Silent']; - let actual = findAnagrams('LISTEN', ['Listen', 'Silent', 'LISTEN']); + const expected = ['Silent']; + const actual = findAnagrams('LISTEN', ['Listen', 'Silent', 'LISTEN']); expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); }); }); From 6ca145f8fb364609f45ba63ecf573b24a3cb6737 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 15 Jan 2025 13:01:32 +0000 Subject: [PATCH 4/4] [CI] Format code --- exercises/practice/anagram/anagram.spec.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/exercises/practice/anagram/anagram.spec.js b/exercises/practice/anagram/anagram.spec.js index 7992d2c5f8..c6dfe5385c 100644 --- a/exercises/practice/anagram/anagram.spec.js +++ b/exercises/practice/anagram/anagram.spec.js @@ -7,7 +7,12 @@ const areSetsEqual = (setA, setB) => describe('Anagram', () => { test('no matches', () => { const expected = []; - const actual = findAnagrams('diaper', ['hello', 'world', 'zombies', 'pants']); + const actual = findAnagrams('diaper', [ + 'hello', + 'world', + 'zombies', + 'pants', + ]); expect(areSetsEqual(new Set(expected), new Set(actual))).toEqual(true); });