diff --git a/1-js/01-a/1-a1/1-camelcase/solution/index.js b/1-js/01-a/1-a1/1-camelcase/solution/index.js index a59eae9c..a4edefb4 100644 --- a/1-js/01-a/1-a1/1-camelcase/solution/index.js +++ b/1-js/01-a/1-a1/1-camelcase/solution/index.js @@ -1,2 +1 @@ - -console.log("Hello"); \ No newline at end of file +function camelize(str) {return str.split('-').map((word, index) => index == 0 ? word : word[0].toUpperCase() + word.slice(1)).join('');} diff --git a/1-js/01-a/1-a1/1-camelcase/source/index.js b/1-js/01-a/1-a1/1-camelcase/source/index.js index 69d903f5..c420d5da 100644 --- a/1-js/01-a/1-a1/1-camelcase/source/index.js +++ b/1-js/01-a/1-a1/1-camelcase/source/index.js @@ -1,3 +1,10 @@ function camelize(str) { - /* your code */ -} \ No newline at end of file + return str + .split('-') // разбивает 'my-long-word' на массив ['my', 'long', 'word'] + .map( + // Переводит в верхний регистр первые буквы всех элементом массива за исключением первого + // превращает ['my', 'long', 'word'] в ['my', 'Long', 'Word'] + (word, index) => index == 0 ? word : word[0].toUpperCase() + word.slice(1) + ) + .join(''); // соединяет ['my', 'Long', 'Word'] в 'myLongWord' +} diff --git a/1-js/01-a/1-a1/1-camelcase/source/test.js b/1-js/01-a/1-a1/1-camelcase/source/test.js index bcf5e955..dadbd1a4 100644 --- a/1-js/01-a/1-a1/1-camelcase/source/test.js +++ b/1-js/01-a/1-a1/1-camelcase/source/test.js @@ -1,19 +1,18 @@ describe("camelize", function() { it("leaves an empty line as is", function() { - assert.equal(camelize(""), ""); + expect(camelize("")).toEqual(""); }); it("turns background-color into backgroundColor", function() { - assert.equal(camelize("background-color"), "backgroundColor"); + expect(camelize("background-color")).toEqual(["background", "color"]) }); it("turns list-style-image into listStyleImage", function() { - assert.equal(camelize("list-style-image"), "listStyleImage"); + expect(camelize("list-style-image")).toEqual("listStyleImage"); }); it("turns -webkit-transition into WebkitTransition", function() { - assert.equal(camelize("-webkit-transition"), "WebkitTransition"); + expect(camelize("-webkit-transition")).toEqual("WebkitTransition") }); - -}); \ No newline at end of file +}); diff --git a/1-js/02-b/1-b1/2-hoverintent/solution/hoverIntent.js b/1-js/02-b/1-b1/2-hoverintent/solution/hoverIntent.js index 44bd2745..c9b307aa 100644 --- a/1-js/02-b/1-b1/2-hoverintent/solution/hoverIntent.js +++ b/1-js/02-b/1-b1/2-hoverintent/solution/hoverIntent.js @@ -1,4 +1,4 @@ -class HoverIntent { +export default class HoverIntent { constructor({ sensitivity = 0.1, // speed less than 0.1px/ms means "hovering over an element" diff --git a/1-js/02-b/1-b1/2-hoverintent/source/hoverIntent.js b/1-js/02-b/1-b1/2-hoverintent/source/hoverIntent.js index b73c6257..9fd479a4 100644 --- a/1-js/02-b/1-b1/2-hoverintent/source/hoverIntent.js +++ b/1-js/02-b/1-b1/2-hoverintent/source/hoverIntent.js @@ -1,6 +1,6 @@ // Here's a brief sketch of the class // with things that you'll need anyway -class HoverIntent { +export default class HoverIntent { constructor({ sensitivity = 0.1, // speed less than 0.1px/ms means "hovering over an element" @@ -25,12 +25,9 @@ class HoverIntent { elem.addEventListener("mouseout", this.onMouseOut); // continue from this point - } onMouseOver(event) { - console.error(console.log); - console.log("OVER", event); /* ... */ } diff --git a/1-js/02-b/1-b1/2-hoverintent/source/index.html b/1-js/02-b/1-b1/2-hoverintent/source/index.html index c1d30b66..3ad401bb 100644 --- a/1-js/02-b/1-b1/2-hoverintent/source/index.html +++ b/1-js/02-b/1-b1/2-hoverintent/source/index.html @@ -1,5 +1,4 @@ -
12 : @@ -9,7 +8,9 @@ - \ No newline at end of file + diff --git a/1-js/02-b/1-b1/2-hoverintent/source/index.spec.html b/1-js/02-b/1-b1/2-hoverintent/source/index.spec.html new file mode 100755 index 00000000..7c0d3236 --- /dev/null +++ b/1-js/02-b/1-b1/2-hoverintent/source/index.spec.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + +
+ 12 : + 30 : + 00 +
+ + + + diff --git a/1-js/02-b/1-b1/2-hoverintent/source/test.js b/1-js/02-b/1-b1/2-hoverintent/source/test.js index ebfc8625..aad3bca0 100644 --- a/1-js/02-b/1-b1/2-hoverintent/source/test.js +++ b/1-js/02-b/1-b1/2-hoverintent/source/test.js @@ -1,5 +1,6 @@ -describe("hoverIntent", function() { +import HoverIntent from './hoverIntent.js'; +describe("hoverIntent", function() { function mouse(eventType, x, y, options) { let eventOptions = Object.assign({ bubbles: true, @@ -16,14 +17,15 @@ describe("hoverIntent", function() { let isOver; let hoverIntent; + let clock; - before(function() { - this.clock = sinon.useFakeTimers(); + beforeAll(function() { + clock = jasmine.clock().install(); }); - after(function() { - this.clock.restore(); + afterAll(function() { + clock.uninstall(); }); @@ -49,13 +51,13 @@ describe("hoverIntent", function() { it("mouseover -> when the pointer just arrived, no tooltip", function() { mouse('mouseover', 10, 10); - assert.isFalse(isOver); + expect(isOver).toBeFalse(); }); it("mouseover -> after a delay, the tooltip shows up", function() { mouse('mouseover', 10, 10); - this.clock.tick(100); - assert.isTrue(isOver); + clock.tick(100); + expect(isOver).toBeTrue(); }); it("mouseover -> followed by fast mouseout leads doesn't show tooltip", function() { @@ -64,8 +66,8 @@ describe("hoverIntent", function() { () => mouse('mouseout', 300, 300, { relatedTarget: document.body}), 30 ); - this.clock.tick(100); - assert.isFalse(isOver); + clock.tick(100); + expect(isOver).toBeFalse(); }); @@ -77,8 +79,8 @@ describe("hoverIntent", function() { i ); } - this.clock.tick(200); - assert.isTrue(isOver); + clock.tick(200); + expect(isOver).toBeTrue(); }); it("mouseover -> fast move -> no tooltip", function() { @@ -89,8 +91,8 @@ describe("hoverIntent", function() { i ); } - this.clock.tick(200); - assert.isFalse(isOver); + clock.tick(200); + expect(isOver).toBeTrue(); }); });