Last active
February 11, 2019 16:33
-
-
Save bernardo-cs/1c9e249988b02571b1e54a44f4d8091a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* QUESTION 1: | |
* Write a code snippet that would transform "animalCollective" into "expected" | |
*/ | |
const animalCollective = [ | |
{type: 'dog', name: 'bobi'}, | |
{type: 'fish', name: 'glup'}, | |
{type: 'fish', name: 'glup the second'}, | |
{type: 'cat', name: 'Aaron'} | |
]; | |
const expected = { | |
fish: [ | |
{type: 'fish', name: 'glup'}, | |
{type: 'fish', name: 'glup the second'} | |
], | |
cat: [{type: 'cat', name: 'Aaron'}], | |
dog: [{type: 'dog', name: 'bobi'}] | |
} | |
/* | |
* QUESTION 2: | |
* What's the value of "arrayOfStrings" after evaluation ? Why ? | |
*/ | |
const arrayOfStrings = ['a', 'b', 'c'].forEach(v => 'a'); | |
/* | |
* QUESTION 3: | |
* What's the value of "anotherArrayOfStrings" after evaluation ? Why ? | |
*/ | |
const anotherArrayOfStrings = ['a', 'b', 'c'].map(v => 'a'); | |
/* | |
* QUESTION 4: | |
* What's the value of "ben" and "userNames" after the evaluation of the following snippet ? Why ? | |
*/ | |
const ben = {name: 'Ben', age: 2 }; | |
const tom = {name: 'Tom', age: 3 }; | |
const users = [ben, tom]; | |
const userNames = users.map(user => user.name).join(); | |
/* | |
* QUESTION 5: | |
* What's the value of "ben" and "myNames" after the evaluation of the following snippet ? Why ? | |
*/ | |
const ben = {name: 'Ben', age: 2 }; | |
const tom = {name: 'Tom', age: 3 }; | |
const users = [ben, tom]; | |
const myNames = users.map(user => { | |
user.name = `My name is ${user.name}`; | |
}).join(); | |
/* | |
* QUESTION 6: | |
* Name 1 advantage and 1 disavantage of using immutable datastructures. | |
*/ | |
/* | |
* QUESTION 7: | |
* Given that we are using RxJS. What will be printed to the console when the following snippet runs ? | |
*/ | |
import { Subject } from 'rxjs'; | |
import { scan } from 'rxjs/operators'; | |
const actionDispatcher = new Subject(); | |
const state$ = actionDispatcher.asObservable().pipe(scan((currentState, action) => { | |
switch(action.type) { | |
case 'reset': | |
return action.payload | |
case 'add': | |
return action.payload + currentState | |
} | |
throw new Error('Unkown action type'); | |
}, 0)); | |
state$.subscribe(state => console.log(state)); | |
actionDispatcher.next({type: 'add', payload: 1}); | |
actionDispatcher.next({type: 'add', payload: 2}); | |
actionDispatcher.next({type: 'reset', payload: 0}); | |
actionDispatcher.next({type: 'add', payload: 3}); | |
/* | |
* QUESTION 8: | |
* Rewrite the snippet on question 8 to use Typescript. If you don't know RxJS typings rewrite question 1. | |
*/ | |
/* | |
* QUESTION 9: | |
* What is the difference between type checking at compiletime and type checking runtime ? | |
* Which kind of type checking is used by typescript ? Which kind of type checking is used by javascript ? | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment