translating
This commit is contained in:
parent
2b874a73be
commit
928cd2731b
165 changed files with 2046 additions and 2967 deletions
|
@ -0,0 +1,8 @@
|
|||
function camelize(str) {
|
||||
return str
|
||||
.split('-') // my-long-word -> ['my', 'long', 'word']
|
||||
.map(
|
||||
(word, index) => index == 0 ? word : word[0].toUpperCase() + word.slice(1)
|
||||
) // ['my', 'long', 'word'] -> ['my', 'Long', 'Word']
|
||||
.join(''); // ['my', 'Long', 'Word'] -> myLongWord
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
describe("camelize", function() {
|
||||
|
||||
it("leaves an empty line as is", function() {
|
||||
assert.equal(camelize(""), "");
|
||||
});
|
||||
|
||||
it("turns background-color into backgroundColor", function() {
|
||||
assert.equal(camelize("background-color"), "backgroundColor");
|
||||
});
|
||||
|
||||
it("turns list-style-image into listStyleImage", function() {
|
||||
assert.equal(camelize("list-style-image"), "listStyleImage");
|
||||
});
|
||||
|
||||
it("turns -webkit-transition into WebkitTransition", function() {
|
||||
assert.equal(camelize("-webkit-transition"), "WebkitTransition");
|
||||
});
|
||||
|
||||
});
|
19
1-js/4-data-structures/8-array-methods/1-camelcase/task.md
Normal file
19
1-js/4-data-structures/8-array-methods/1-camelcase/task.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
importance: 5
|
||||
|
||||
---
|
||||
|
||||
# Translate border-left-width to borderLeftWidth
|
||||
|
||||
Write the function `camelize(str)` that changes dash-separated words like "my-short-string" into camel-cased "myShortString".
|
||||
|
||||
That is: removes all dashes, each word after dash becomes uppercased.
|
||||
|
||||
Examples:
|
||||
|
||||
```js
|
||||
camelize("background-color") == 'backgroundColor';
|
||||
camelize("list-style-image") == 'listStyleImage';
|
||||
camelize("-webkit-transition") == 'WebkitTransition';
|
||||
```
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue