Last changes

This commit is contained in:
Volodymyr Shevchuk 2021-05-03 15:15:32 +03:00
parent b24b05d3ca
commit fdc015e1fa
8 changed files with 59 additions and 32 deletions

View file

@ -1,3 +1,10 @@
function camelize(str) {
/* your code */
}
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'
}

View file

@ -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")
});
});
});