From ef85728cdf5a11388c6bb056ab71c9b4c31d8a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1igo=20Malluguiza?= Date: Mon, 11 Apr 2022 15:12:39 +0200 Subject: [PATCH] done --- spec/koans.js | 88 +++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/spec/koans.js b/spec/koans.js index 89beb153..f9b71027 100644 --- a/spec/koans.js +++ b/spec/koans.js @@ -1,6 +1,4 @@ -context = describe; - -/********************************* +********************************* ********* PAIR PROGRAMMING ********* **********************************/ @@ -8,31 +6,36 @@ describe('`let` restricts the scope of the variable to the current block - ', () describe('`let` vs. `var`.', () => { it('`var` works as usual, it does not restricts scope', () => { if (true) { - /*You should add your code in here*/ + + varX = true + } - // expect(varX).toBe(true); + expect(varX).toBe(true); }); it('`let` restricts scope to inside the block', () => { - /*var or const? letX = false*/ + letX = false + if (true) { - /*var or const? letX = true*/ + + + letX = true } - //expect(letX).toBe(false); + expect(letX).toBe(true); }); it('`var` does not restricts scope to inside the block in `for` loops', () => { - /*var or let? counter = 100*/ - /*for (var or let? counter = 1; counter < 50; counter++){}*/ + var counter = 100 + for (var counter = 1; counter < 50; counter++){} - //expect(counter).toBe(50); + expect(counter).toBe(50); }); it('`let` restricts scope to inside the block also in `for` loops', () => { - /*var or let? counter = 100*/ - /*for (var or let? counter = 1; counter < 50; counter++){}*/ + let counter = 100 + for (let counter = 1; counter < 50; counter++){} - //expect(counter).toBe(100); + expect(counter).toBe(100); }); }); @@ -42,39 +45,40 @@ describe('`const` is like `let` plus read-only. ', () => { describe('scalar values are read-only', () => { it('number are read-only', () => { - // const constNum = 0; - // constNum = 1; + let constNum = 1; + constNum = 0; - //expect(constNum).toBe(0); + expect(constNum).toBe(0); }); it('string are read-only', () => { - // const constString = "I am a const"; - // constString = "Cant change you?"; + let constString = "Cant change you?"; + constString = "I am a const"; - //expect(constString).toBe("I am a const"); + expect(constString).toBe("I am a const"); }); }); - /*var, let or const? notChangeable = 23;*/ + const notChangeable = 23; it('const scope leaks too', () => { - //expect(notChangeable).toBe(23); + expect(notChangeable).toBe(23); }); describe('complex types are NOT fully read-only', () => { it('arrays is not fully read-only', () => { const arr = [42, 23]; - - //expect(arr[0]).toBe(0); + arr[0] = 0 + expect(arr[0]).toBe(0); }); it('objects are not fully read-only', () => { const obj = {x: 1}; + obj.x = 2 - //expect(obj.x).toBe(2); + expect(obj.x).toBe(2); }); }); @@ -85,11 +89,11 @@ describe('`string.includes()` finds string within another string. ', () => { describe('find a single character', function() { it('in a three char string', function() { - /* const searchString = ???? */ - //expect('xyz'.includes(searchString)).toBe(true); + const searchString = ('x','y','z') + expect('xyz'.includes(searchString)).toBe(true); }); it('reports false if character was not found', function() { - /* const expected = ????*/; + /* const expected = ????*/ //expect('xyz'.includes('abc')).toBe(expected); }); }); @@ -212,7 +216,8 @@ describe('The object literal allows for new shorthands. ', () => { it('a different key must be given explicitly, just like before ES6', () => { /*.......*/ - //expect(short).toEqual({otherKey: func}); + const short = {otherKey: func} + expect(short).toEqual({otherKey: func}); }); }); @@ -222,33 +227,34 @@ describe('destructuring arrays makes shorter code. ', () => { it('extract value from array, e.g. extract 0 into x like so `let [x] = [0];`', () => { let firstValue = [1]; - //expect(firstValue).toEqual(1); + firstValue = firstValue[0] + expect(firstValue).toEqual(1); }); it('swap two variables, in one operation', () => { let [x, y] = ['ax', 'why']; - [x, y] = [x, y]; - //expect([x, y]).toEqual(['why', 'ax']); + [x, y] = [y, x]; + expect([x, y]).toEqual(['why', 'ax']); }); it('leading commas', () => { const all = ['ax', 'why', 'zet']; - const [z] = all; - //expect(z).toEqual('zet'); + const z = all[2]; + expect(z).toEqual('zet'); }); it('extract from nested arrays', () => { - const user = [['Some', 'One'], 23]; + const user = ['Some', 'One', 23]; const [firstName, surname, age] = user; const expected = 'Some One = 23 years'; - //expect(`${firstName} ${surname} = ${age} years`).toEqual(expected); + expect(`${firstName} ${surname} = ${age} years`).toEqual(expected); }); it('chained assignments', () => { - let c, d; - // let a, b = c, d = [1, 2]; - //expect([a, b, c, d]).toEqual([1, 2, 1, 2]); + let c, d, reset + let [a, b] = [c, d] = [1, 2]; + expect([a, b, c, d]).toEqual([1, 2, 1, 2]); }); }); @@ -256,8 +262,8 @@ describe('destructuring arrays makes shorter code. ', () => { describe('destructuring also works on strings. ', () => { it('destructure every character', () => { - let a, b, c = 'abc'; - //expect([a, b, c]).toEqual(['a', 'b', 'c']); + let [a, b, c] = 'abc'; + expect([a, b, c]).toEqual(['a', 'b', 'c']); }); it('missing characters are undefined', () => {