---
# System prepended metadata

title: FB questions

---

FB questions
===

- flatten array - both in iterative and recursive way - This array can have multiple types: {}, [], "", undefined, null, 123 are all valid types inside the array. 
- Basic JavaScript async stuff (you should know event bubbling, debounce (its variant)... know how to code it). It would be a good idea to be aware of JS closure as well. 
- event emitter - pub/sub
- es6 features - maps, sets, weakmap etc
- write a sample class with member functions using closure/callbacks
- What are the advantages of using ES6 maps over objects? What about using ES6 sets over arrays? 
- design/code a poll widget - Poll Widget question (just know your positioning, relative, static etc know the differences inside out). You might want to know specificity as well.
- Given a picture, how would you hide/show a child picture on hovering on this parent?
- How would you ensure clicking on this picture would go to a specific link?  
- How many times would `addEventListener('scroll', handleScroll);` run as the user looks at their News Feed? And what would be user experience if the `handleScroll` function takes 100ms to execute.  
- Using HTML and CSS, show how you would create an image that would display another image (aligned to the bottom, right) when the user hovers over the image. ex. The Facebook "edit profile picture" icon  
- You are given an array of N elements in the form "property1: value1; property2: value2;...;propertyX: valueX;" for some some N and any X. There is also another array of M elements of the form "property: value". You are supposed to write an algorithm to remove every element in the N length array that has a "property: value" pair in the M length array. The trick is that the most intuitive solution of iterating through the M array and filtering the N array at each element is already written. You must come up with a solution that solves the problem in less than O(NM) time.  
- How would you ensure the child is positioned in the top right of the parent picture
- If you have 500 revisions of a program, write a program that will find and return the FIRST bad revision given a isBad(revision i) function. 
- Tell me a difficult problem you had to solve.
- Given an input array and another array that describes a new index for each element, mutate the input array so that each element ends up in their new index. Discuss the runtime of the algorithm and how you can be sure there won't be any infinite loops.
- If you were building a search tool and wanted search results to pop up as you typed but the server call was taxing, write a function that gets called on every key down but calls the server when the user stops typing for 400ms.  
- what's the differences between queue and stack, what is event propagation, what is a time complexity to traverse the balanced binary tree, etc
- Implement a simple store class with set(Node, value), get(Node) and has(Node) methods, which store a given Nodes with corresponding values.
- Implement a square root function.
- Given a value N, return the corresponding string according to this pattern.
    1
    11
    21
    1211
    111221
    312211  
- Javascript and DOM traversal  - walk-the-dom method
- Javascript Questions about functions you can perform on strings
- CSS related questions like difference between block and inline
- build a layout for a calendar where events added on the calendar that collide in time can't visually collide but should take same width with the events that they collide in time with
- Given 2 identical DOM trees (but not equal) and one element of the first DOM tree, how would you find this element in the second DOM tree? 
- optimize a function from n2 to good time
    - ```function(itemsList, excludesList) {}```
    -   ```// could be potentially more than 3 keys in the object above
        items = [
        {color: 'red', type: 'tv', age: 18},
        {color: 'silver', type: 'phone', age: 20}
        ...
        ]

        excludes = [
        {k: 'color', v: 'silver'},
        {k: 'type', v: 'tv'},
        ....
        ]
        function excludeItems(items, excludes) {
           excludes.forEach(pair => {
              items = items.filter(item => item[pair.k] === item[pair.v]);
           });
           return items; }
           ```
     
- What's the difference between call and apply (JavaScript)  
- what is time complexity of traversing through the DOM
- first question is about data structure, given two arrays, one of them is a map to another, you need to traverse and exclude from array objects according to the map, in general they expect from you to build an map object from key+value but you have to use ES6 MAP where key can be stored as object and not as string or ASCII coded string
- setTimeout browser api, you will be asked to clean all timeouts, the answer is to override setTimeout and store all of them in stuck and clean them if needed.  
- Pub-Sub using Set https://gist.github.com/robinpokorny/d743ed9e0bc5214f79076a16c8e44a8f
- https://frontendmasters.com/books/front-end-handbook/2018/learning/dom.html
- https://www.careercup.com/page?pid=facebook-interview-questions&job=front-end-software-engineer-interview-questions
- https://trello.com/b/UxxGapYq/facebook
- https://www.thatjsdude.com/interview/
- 
           
