- Create GitHub repo named
homeWorks(how?) - Create folder
hw-1 - Implement next function in separeted files
leftPad('foo', 5)
// => " foo"
leftPad('foobar', 6)
// => "foobar"
leftPad(1, 2, 0)
// => "01"
leftPad(17, 5, 0)
// => "00017" Create two different realizations (with strings and arrays) then compare they performance. (how?)
mapArray([1, 2, 3, 4], (el) => ++el)
// => [2, 3, 4, 5]Function should get two params: function mapArray(arr, fun) { ... };
* arr - Array which will be transformed
* fun - Function which will transform array items one by one
Incoming array should be immutable! (what?)
This function should work like previous but first parameter also could be an object
map([1, 2, 3, 4], (el) => ++el)
// => [2, 3, 4, 5]
map({a: 1, b: 2, c: 3});
// => {a: 2, b: 3, c: 4}Should transform array of arrays to one array where each item is a primitive
flatten([1, [2, 3], [[4], [5, 6]]]);
// => [1, 2, 3, 4, 5, 6]Should get two params function fallback(obj, fallback) { ... };
+ obj - Object with empty field (null, '', undefined)
+ fallback - First object should get his empty fields using values from this one
```js
let obj = {
id: 0,
info: {
name: 'Alex',
surname: '',
age: null
},
description: ''
};
let fallbackObj = {
id: 2,
info: {
name: 'default name',
surname: 'default surname',
age: 22
},
description: 'default description'
}
fallback(obj, fallbackObj);
// => { id: 2, info: { name: 'Alex', surname: 'default surname', age: 22 }, description: 'default description' }
```
- Add each file to separated commits at
feature/hw-1branch - Push to remote and create pull request to
masterbranch