these are some samples of coding excercises I have resolved in past interviews
See also:
| const shallowCompare = (obj1, obj2) => | |
| typeof obj1 === 'object' && typeof obj2 === 'object' | |
| ? Object.keys(obj1).length === Object.keys(obj2).length && | |
| Object.keys(obj1).every( | |
| key => obj2.hasOwnProperty(key) && obj1[key] === obj2[key] | |
| ) | |
| : obj1 === obj2 | |
| const memoizeByProps = (...props) => Component => | |
| React.memo(Component, (prevProps, nextProps) => |
| const loop = { | |
| timer: null, | |
| count: 0, | |
| start(fn, time=1000, limit = 100) { | |
| fn(this.stop.bind(this), this.count); | |
| this.count++; | |
| if (this.count < limit) { | |
| this.timer = setTimeout(() => this.start(fn, time, limit), time) | |
| } else { | |
| this.stop() |
| // @params: N functions that should return an Object | |
| // @returns a fn that will pass all arg to all fns and return an Obj with all outputs merged | |
| const mergeOutputs = (...fns) => (...args) => fns.reduce((out, fn) => ({ | |
| ...out, | |
| ...fn(...args) | |
| }), {}) | |
| // takes one arg | |
| const one = (name) => ({ hello: name, world: name }) |
| const combine = (...fns) => (...args) => fns.reduce((returnValues, fn) => [...returnValues, fn(...args)], []) |
these are some samples of coding excercises I have resolved in past interviews
See also: