Skip to content

Latest commit

 

History

History
81 lines (68 loc) · 2.27 KB

File metadata and controls

81 lines (68 loc) · 2.27 KB

JavaScript basic. Git.

  1. Create GitHub repo named homeWorks (how?)
  2. Create folder hw-1
  3. Implement next function in separeted files

You could use jsbin.com to run your code (how?)

leftPad.js

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.js

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?)

map.js

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}

flatten.js

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]

fallback.js

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' }
```
  1. Add each file to separated commits at feature/hw-1 branch
  2. Push to remote and create pull request to master branch