# 11 mil

Preguntas de entrevista para el puesto de Ingeniero Front End compartidas por los candidatos

## Principales preguntas de entrevista

Ordenar: Relevancia|Popular|Fecha
A un Front End Engineer le preguntaron...8 de abril de 2013

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

25 respuestas

Essentially the same as Anh's answer but less code, assuming ES5 is available var arr = ["a","b","c","d","e","f"]; var indices = [2, 3, 4, 0, 5, 1]; arr = indices.map(function (item, index) { return arr[indices.indexOf(index)]; }); Menos

function reposition(arr, indices) { var newArr = []; // I'm not sure if extra space is allowed. If it is, the solution should be this simple. for(var i = 0; i &lt; arr.length; ++i) { var newIndex = indices[i]; newArr[newIndex] = arr[i]; } return newArr; } var arr = ["a", "b", "c", "d", "e", "f"]; var indices = [2, 3, 4, 0, 5, 1]; reposition(arr, indices); // returns: ["d", "f", "a", "b", "c", "e"] Menos

function repositionElements(arr, indices) { // assert(arr.length === indices.length) var moved = []; for (var i = 0; i &lt; arr.length; i++) { moved.push(false); } var moveFrom, moveTo, itemToMove; for (moveFrom = 0; moveFrom &lt; arr.length; moveFrom++) { itemToMove = arr[moveFrom]; while (!moved[moveFrom]) { moveTo = indices[moveFrom]; var tmpItem = arr[moveTo]; arr[moveTo] = itemToMove; itemToMove = tmpItem; moved[moveFrom] = true; moveFrom = moveTo; } } return arr; } var arr = ["a", "b", "c", "d", "e", "f"], indices = [2, 3, 4, 0, 5, 1]; repositionElements(arr, indices); // returns: ["d", "f", "a", "b", "c", "e"] Menos

Mostrar más respuestas

### Given input: // 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; } 1. Describe what this function is doing... 2. What is wrong with that function ? 3. How would you optimize it ?

24 respuestas

I agree with converting the excludes to an object, but in order to get linear performance that doesn't depend on the number of excluded things, you have to concatenate the k and v into one value to be used as the key in the object: let excludesObject = {}; excludes.forEach(pair =&gt; excludesObject[`\${pair.k}_\${pair.v}`] = true); Then you can check if an item should be excluded in O(k) time where k is the number of keys in an item. And the whole thing will run in O(nk) where n is the number of items. // if there is some key which is found in the excludesObject, the filter will return false items = items.filter(item =&gt; !Object.keys(item).some(key =&gt; excludesObject[`\${key}_\${item[key]}`]); ); Facebook, hire me! lol Menos

function excludeItems(items, excludes) { let excludesMap = excludes.reduce((entry, result)=&gt;{ entry[result.k + result.v] = true; return entry; },{}); return items.reduce( (result, item) =&gt; { let updatedObject = Object.keys(item).reduce( (result,key) =&gt; { if(!excludesMap[key + item[key]]){ result[key] = item[key] } return result; }, {}) result.push(updatedObject) return result; }, []) } Menos

This solution will give much faster and immutable result. You can test with performance.now items.reduce((allItems, item) =&gt; { if(!excludes.some(exclude=&gt;item[exclude.k] === exclude.v)){ allItems.push(item); } return allItems; }, []); Menos

Mostrar más respuestas

### 1. In JavaScript, write a function that takes an array as input that can contain both ints and more arrays (which can also contain an array or int) and return the flattened array. ex. [1, [2, [ [3, 4], 5], 6]] =&gt; [1, 2, 3, 4, 5, 6] 2. 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

12 respuestas

ary.join().split(',');

array.toString().split(',').map(Number), map need because input array has only integer types. Menos

var flatten = function(arr, resultArr) { var result = resultArr || []; for(var i = 0; i &lt; arr.length; i++) { if(Array.isArray(arr[i])) { flatten(arr[i], result); } else { result.push(arr[i]); } } return result; }; Menos

Mostrar más respuestas

### Given a grid of characters output a decoded message. The message for the following would be IROCKA. (diagonally down right and diagonally up right if you can't go further .. you continue doing this) I B C A L K A D R F C A E A G H O E L A D

11 respuestas

as there are 21 characters and you describe a grid, I'm assuming it's 3x7: I B C A L K A D R F C A E A G H O E L A D Starting from the upper left and moving SE till a wall, then moving NE, then moving SE yields IROCLED, not IROCKA. However my human-powered fuzzy search is telling me it's much more likely that the answer is IROCKED, so I'm wondering whether the 1. author misremembered the original grid 2. the author misremembered the correct answer and the grid 3. I misunderstood the question. Menos

var arr = [ ['I','B','C','A','L','K','A'], ['D','R','F','C','A','E','A'], ['G','H','O','E','L','A','D'] ]; var row = 0, col = 0; var totalCols = arr[0].length; var totalRows = arr.length; var msg = ''; while (col &lt; totalCols) { msg += arr[row][col]; // row++ if less than total rows // row-- if back at row 0 row = (row === 0 || row &lt; totalRows - 1) ? row + 1 : row - 1; // always go forward in column col++; } // returns 'IROCLED' Menos

All solutions in here are wrong as they never go back up to the 0th row after first descent. ``` var arr = [ ['I','B','C','A','K','E','A'], ['D','R','F','C','A','E','A'], ['G','H','O','E','L','A','D'] ]; var row = 0, col = 0; var totalCols = arr[0].length; var totalRows = arr.length; var goingDown = false; var msg = ''; while (col &lt; totalCols) { msg += arr[row][col]; // row++ if less than total rows // row-- if back at row 0 if (row === 0 || (row &lt; totalRows - 1 &amp;&amp; goingDown)) { row += 1; goingDown = true; } else { row -= 1; goingDown = false; } // always go forward in column col++; } console.log(msg) // IROCKED ``` Menos

Mostrar más respuestas

### Given an array, return it's flattened structure(skip objects)

10 respuestas

function flatten(input) { return (input || []).reduce(function (prev, current) { if (Array.isArray(current)) { return prev.concat(flatten(current)); } else { prev.push(current); return prev; } }, []); } Menos

function flattenRecursive( a, ret ) { return a.reduce((ret, cur) =&gt; { if (Array.isArray(cur)) { flattenRecursive(cur, ret); } else if(typeof cur !== 'object'){ ret.push(cur); } return ret; }, ret || []) } function flattenIterative( a ) { let ret = []; while( a.length ) { let cur = a.pop(); if (Array.isArray(cur)) { a = [...a, ...cur]; } else if ( typeof cur !== 'object' ){ ret.push(cur) } } return ret.reverse(); } Menos

let flat = (z = []) =&gt; { return !Array.isArray(z) ? [].concat(z) : (z.length &gt; 0) ? flat(z.splice(0, 1)[0]).concat(flat(z)) : z } Menos

Mostrar más respuestas

### What are your greatest technical strengths?

8 respuestas

Management

Social media experience

I am technically sound in using R script for R programming language, base SAS, SAS analytics and Advanced SAS. Menos

Mostrar más respuestas

### Implement a simple store class with set(Node, value), get(Node) and has(Node) methods, which store a given Nodes with corresponding values.

7 respuestas

Since node is object we can store value directly on the node itself. But it become complex and may mess with original object. Luckily we have Symbol come to rescue: class DOMStore { constructor () { this.DOMStoreSymbol = Symbol('DOMStore'); } has (node) { return node[this.DOMStoreSymbol] !== undefined; } set (node, value) { node[this.DOMStoreSymbol] = value; } get (node, defaultValue) { return node[this.DOMStoreSymbol] || defaultValue; } } const e1 = document.createElement('A'); const e2 = document.createElement('P'); const e3 = document.createElement('DIV'); const e4 = document.createElement('TABLE'); const e5 = document.createElement('A'); const map1 = new DOMStore(); const map2 = new DOMStore(); console.assert(map1.has(e1) === false, 'map1 should be empty'); map1.set(e1, 'E1 in map1'); console.assert(map1.has(e1) === true, 'map1 must have e1'); map2.has(e1); console.assert(map2.has(e1) === false, 'map2 should be empty'); map1.set(e2, 1234); map1.set(e3, "String"); map1.set(e4, [1,2,3,4]); console.assert(map1.get(e5, null) === null); console.assert(map1.get(e5) === undefined); console.assert(map1.get(e5, 5) === 5); map1.set(e5, {1: 2, 3: 4}); console.assert(map1.get(e1) === 'E1 in map1'); console.assert(typeof(map1.get(e5)) === 'object'); Menos

Are you able to elaborate on this question? Can each node have multiple values or just 1? The way I interpret what you have written, it just sounds like they are asking for an ES6 Map? ES6 Maps can have objects as keys, so you can use the Node as the key. If you had to code it from scratch without the use of an ES6 Map, something like: class CachedNode { constructor(node, value) { this._node = node; this._value = value; } getNode() { return this._node; } getValue() { return this._value; } setValue(value) { this._value = value; return this; } } class SimpleStore { constructor() { this._container = []; } set(node, value) { let cachedNode; if (this.has(node)) { cachedNode = this.get(node); cachedNode.setValue(value); } else { cachedNode = new CachedNode(node, value); this._container.push(cachedNode); } return this; } // you might want to change this method so it returns the Node's value not the CachedNode. // If you did, that would mean adding another method to get the CachedNode. Easy enough. get(node) { return this._container.find((cachedNode) =&gt; { return cachedNode.getNode() === node; }); } has(node) { return !!this.get(node); } } If it needed to store multiple values against a node, then just change the single value for a Set or Array. Menos

The tricky part of the question was on how to store a DOM Node which is an object as an old javascript object key. I can't recall was it about 1 to 1 relationship or 1 to many, but it is really doesn't matter because the later gives just a small overhead. I suppose your solution is pretty what they were expected from the task, starting from explaining ES6 Map and ending up with an old javascript solution. Menos

Mostrar más respuestas

### // Given var endorsements = [ { skill: 'css', user: 'Bill' }, { skill: 'javascript', user: 'Chad' }, { skill: 'javascript', user: 'Bill' }, { skill: 'css', user: 'Sue' }, { skill: 'javascript', user: 'Sue' }, { skill: 'html', user: 'Sue' } ]; getSkills = (endorsements) => { // Result // [ // { skill: 'javascript', user: ['Chad', 'Bill', 'Sue'], count: 3 }, // { skill: 'css', user: ['Sue', 'Bill'], count: 2 }, // { skill: 'html', user: ['Sue'], count: 1 } // ]; } see this image: http://i.imgur.com/UIeB3n4.png

7 respuestas

let endorsements = [ { skill: 'css', user: 'Bill' }, { skill: 'javascript', user: 'Chad' }, { skill: 'javascript', user: 'Bill' }, { skill: 'css', user: 'Sue' }, { skill: 'javascript', user: 'Sue' }, { skill: 'html', user: 'Sue' }, ]; let x = endorsements.reduce((acc, { skill, user }) =&gt; { if (skill in acc) { acc[skill] = { user: [...acc[skill]['user'], user], count: acc[skill]['count'] + 1, skill: skill, }; } else { acc[skill] = { user: [user], count: 1, skill: skill, }; } return acc; }, {}); console.log(Object.values(x)); Menos

I did in a different way let outPut = []; let skillMap = {}; for (let char of endorsements) { if (char['skill'] in skillMap) { skillMap[char['skill']] = [...skillMap[char['skill']], char['user']]; } else { skillMap[char['skill']] = [char['user']]; } } for (let key in skillMap) { let skillObj = {}; skillObj['skill'] = key; skillObj['user'] = skillMap[key]; skillObj['count'] = skillMap[key].length; outPut.push(skillObj); } return outPut.sort((a, b) =&gt; b.count - a.count); Menos

getSkills = endorsements =&gt; { const skillMap = {}; // assumption - each object has all the properties, nothing is missing endorsements.forEach((item, index) =&gt; { const { skill, user } = item; if (!skillMap[skill]) { skillMap[skill] = {}; skillMap[skill]["user"] = []; // skillMap[skill]["user"].push(user); skillMap[skill]["count"] = 0; } skillMap[skill]["user"].push(user); skillMap[skill]["count"] += 1; // } }); return Object.keys(skillMap).map(key =&gt; [ { skill: key, ...skillMap[key] } ]); }; Menos

Mostrar más respuestas

### Write an emitter class: /* emitter = new Emitter(); // 1. Support subscribing to events. sub = emitter.subscribe('event_name', callback); sub2 = emitter.subscribe('event_name', callback2); // 2. Support emitting events. // This particular example should lead to the `callback` above being invoked with `foo` and `bar` as parameters. emitter.emit('event_name', foo, bar); // 3. Support unsubscribing existing subscriptions by releasing them. sub.release(); // `sub` is the reference returned by `subscribe` above */

7 respuestas

var Emitter = function() { this.events = {}; }; var Subscription = function(event, callback, event_listeners, key) { this.event = event; this.callback = callback; this.event_listeners = event_listeners; this.key = key; }; Subscription.prototype.release = function () { var ret = false; if (this.event_listeners[this.key]) { delete this.event_listeners[this.key]; ret = true; } return ret; }; Emitter.prototype.subscribe = function(event_name, callback) { if (!this.events.hasOwnProperty(event_name)) { this.events[event_name]; this.events[event_name] = []; } var subscription = new Subscription(event_name, callback, this.events[event_name], this.events[event_name].length); this.events[event_name].push(subscription); return subscription; }; Emitter.prototype.emit = function(event_name, param1, param2) { var subs = this.events[event_name]; return subs.forEach(function(sub) { return sub.callback.call(sub, param1, param2); }); } Menos

class Emitter { constructor() { this.events = {}; } on(name, handler) { (this.events[name] || (this.events[name] = [])).push(handler); return this.off.bind(this, name, handler); } off(name, handler) { this.events[name] &amp;&amp; this.events[name].filter(handle =&gt; handle === handler); } emit(name, ...payload) { this.events[name].map(handler =&gt; handler(...payload)); } } Menos

class Emitter { constructor() { this.cb = {}; } subscribe = (name, cb) =&gt; { this.cb[name] = cb; return {release: () =&gt; delete this.cb[name]}; } emit = (name, ...arges) =&gt; { this.cb[name](arges); } }; e = new Emitter(); rm1 = e.subscribe("f1", p =&gt; console.log("f1111 ", p)); rm2 = e.subscribe("f2", p =&gt; console.log("f222 ", p)); e.emit("f1", "GGG", "ssskoko") e.emit("f1", "GGG", "ssskoko", 1,5,7,2,3) Menos

Mostrar más respuestas

### In your opinion, what is our company's single most important metric?

7 respuestas

Reservations per day I guess

It's always revenue my man/woman

"It's always revenue my man/woman." I hope you understand how irrelevant you observation is in the context of this position. So no, it's not "always revenue." Menos

Mostrar más respuestas
Viendo 1-10 de 11.044 preguntas de entrevista

## Consultar preguntas de entrevista para empleos similares

Glassdoor ha recopilado 11.044 preguntas de entrevista e informes de entrevistas para el puesto de Ingeniero front end. Prepárate la entrevista y consigue el empleo perfecto.