diff --git a/.vscode/settings.json b/.vscode/settings.json index 83cbd3c..01cafe3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,4 +3,5 @@ "files.autoSaveDelay": 500, "editor.minimap.enabled": false, "workbench.colorTheme": "Default Dark+", + "editor.tabSize": 2 } \ No newline at end of file diff --git a/minesweeper/package.json b/bonus2/package.json similarity index 100% rename from minesweeper/package.json rename to bonus2/package.json diff --git a/bonus2/src/solution.js b/bonus2/src/solution.js new file mode 100644 index 0000000..a6b156a --- /dev/null +++ b/bonus2/src/solution.js @@ -0,0 +1,22 @@ +exports.solve = function (param) { + if (param === 'a') { + return false; + } + return true; +} + +const solveConsonants = function(string) { + return string.split(/[ae1yio]+/i).sort((a, b) => b.length - a.length)[0]; +} + +const isConsonant = (letter) => { + let consonants = [ + 'b', 'c', 'd', 'f', 'g', 'h', + 'j', 'k', 'l', 'm', 'n', 'p', + 'r', 's', 't', 'w', 'z']; + + return consonants.includes(letter); +} + +exports.isConsonant = isConsonant; +exports.solveConsonants = solveConsonants \ No newline at end of file diff --git a/bonus2/src/test.js b/bonus2/src/test.js new file mode 100644 index 0000000..a7b7071 --- /dev/null +++ b/bonus2/src/test.js @@ -0,0 +1,58 @@ +const { solve, solveConsonants, isConsonant } = require('./solution'); + +describe('solve', () => { + it('should be consonant', () => { + expect( solve('b') ).toBe(true); + }); + + it('should not be vowel', () => { + expect( solve('a') ).toBe(false); + }); + + it('should return substring', () => { + expect(isConsonant('b')).toBe(true); + }); + + it('should return substring', () => { + expect(isConsonant('a')).toBe(false); + }); + + it('should return true if parameter if consonant', () => { + expect(isConsonant('d')).toBe(true); + }); +}); + +describe('solveConsonants', () => { + it('should return only consonants', () => { + expect(solveConsonants('abc')).toBe('bc'); + }) + + it('should return substring', () => { + expect(solveConsonants('bcdabcdbcd')).toBe('bcdbcd'); + }); + + it('should return substring', () => { + expect(solveConsonants('bcdabcdbcda')).toBe('bcdbcd'); + }); + + it('should return substring', () => { + expect(solveConsonants('bcd1bcdbcda')).toBe('bcdbcd'); + }); + + it('should return substring', () => { + expect(solveConsonants('bcdghk')).toBe('bcdghk'); + }); +}) + + + +// check === +// expect(1).toBe(1) + +// check deep equality +// expect([1, 2]).toEqual([1, 2]) + +// spółgłoski: +// b, c, d, f, g, h, j, k, l, m, n, p, r, s, t, w, z +// samogłoski: +// a, e, i, o, u, y \ No newline at end of file diff --git a/minesweeper/yarn.lock b/bonus2/yarn.lock similarity index 100% rename from minesweeper/yarn.lock rename to bonus2/yarn.lock diff --git a/minesweeper/src/solution.js b/minesweeper/src/solution.js deleted file mode 100644 index 4f4be86..0000000 --- a/minesweeper/src/solution.js +++ /dev/null @@ -1,38 +0,0 @@ -exports.solve = function (param) { - if(param.some(row => row.length !== param.length)) { - throw new Error - } - - - - if (!param.length || param.some(value => !isValid(value))) { - return '?'; - } - return returnIdentical(param); -} - -exports.solveRow = function (param) { - if (!param.length || param.some(value => !isValid(value))) { - throw new Error(); - } - return returnIdentical(param); -} - -const returnIdentical = function (params) { - for (let index = 0; index < params.length; index++) { - if (params[index] !== params[0]) { - return '?'; - } - } - - return params[0]; -} - -const isValid = function (param) { - return param === 'X' || param === 'O'; -} - - - -exports.isValid = isValid; -exports.returnIdentical = returnIdentical; \ No newline at end of file diff --git a/minesweeper/src/test.js b/minesweeper/src/test.js deleted file mode 100644 index 4370a8e..0000000 --- a/minesweeper/src/test.js +++ /dev/null @@ -1,65 +0,0 @@ -const { solve, solveRow, isValid, returnIdentical } = require('./solution'); - -it('is one element', () => { - expect( solveRow(['X']) ).toBe('X'); -}); - -it('works', () =>{ - expect(() => solveRow([])).toThrow(); -}); - -it('works', () =>{ - expect(() => solveRow(['+'])).toThrow(); -}); - -it('works', () =>{ - expect(isValid('X')).toBe(true); - expect(isValid('O')).toBe(true); - expect(isValid('-')).toBe(false); - expect(isValid([])).toBe(false); -}); - -it('works', () =>{ - expect(() => solveRow(['Y', 'Y', 'X'])).toThrow(); - expect(() => solveRow(['X', 'Y', 'Y'])).toThrow() -}); - -it('works', () =>{ - expect( returnIdentical(['Y', 'Y', 'Y'])).toBe('Y'); -}); - -it('works', () =>{ - expect( returnIdentical(['?', 'X', 'Y'])).toBe('?'); -}); - -it('works', () =>{ - expect( solveRow(['X', 'X', 'X'])).toBe('X'); - expect( solveRow(['O', 'O', 'O'])).toBe('O'); -}); - -it('works', () =>{ - expect( solveRow(['O', 'X', 'X'])).toBe('?'); -}); - -it('works', () =>{ - expect( solve([['X', 'X'], ['Y', 'Y']])).toBe('?'); -}); - -it('works', () =>{ - expect( () => solve([['X', 'X', 'Y'], ['Y', 'Y', 'Y']])).toThrow(); -}); - - -// it('works', () =>{ -// expect( solve([ -// ['X', 'X', 'X'], -// ['Y', 'Y', 'X'], -// ['Y', 'Y', 'X'] -// ])).toBe('X'); -// }); - -// check === -// expect(1).toBe(1) - -// check deep equality -// expect([1, 2]).toEqual([1, 2])