Web Development Engineer was asked...February 25, 2017

↳

const Sum = a => b => c => a + b + c;

↳

``` // Lexically nested function definitions defined within enclosing function function Sum(arg0) { function Inner1(arg1) { function Inner2(arg2) { return arg0 + arg1 + arg2; } return Inner2; } return Inner1; } console.log(Sum(3)(4)(5)); ``` Less

↳

var sum=0; // global variable function Sum(num){ sum=num+sum; return Sum; } Sum(3)(4)(5); Less

Web Development Engineer was asked...June 18, 2013

↳

#center{width: 100px; height: 50px; position: fixed; top: 0; left: 0; right: 0; bottom: 0; margin: auto;} Less

↳

wrong answer. u need to also margin it negative

↳

. container{ Position : absolute; Width : 200px; Top : 50℅; Left : 50℅; Transform : translate(-50℅) } Less

Web Development Engineer was asked...February 17, 2016

↳

The most upvoted answer on this has a run time complexity of O(m * n) where m and n are the arrays. This is solvable in O(n) by using a hash map, by sacrificing space for complexity: var Array1 = ["a", "b", "c", "d", "e", "f", "c"]; var Array2 = ["c", "x", "y", "f", "c"]; let hash = {}; let result = []; // loop over the largest for (let i = 0; i < Array1.length; i++) { if (!hash[Array1[i]]) { hash[Array1[i]] = 1; } } for (let i = 0; i < Array2.length; i++) { if (hash[Array2[i]]) { result.push(Array2[i]); delete hash[Array2[i]]; } } console.log(result); Less

↳

var Array1 = ["a", "b", "c", "d", "e", "f"]; var Array2 = ["c", "x", "y", "f"]; Array1 = Array1.filter(function(val) { return Array2.indexOf(val) !== -1; }); Less

↳

I think that the last solution suggested might still return duplicates. For example if array1 = [1,2,3] and array2 = [2,2,2] we will get the result of [2,2]. This is another solution in O(n) - function findDuplicates(arr1, arr2) { var dict = {}; var duplicates = {}; for (i = 0; i < arr1.length; i++ ) { dict[arr1[i]] = 1; } for (i = 0; i < arr2.length; i++ ) { if (dict[arr2[i]]) { duplicates[arr2[i]] = arr2[i]; } } return Object.values(duplicates); } Less

Web Development Engineer was asked...May 24, 2009

↳

#Assumes positive numbers def divide(num, divide_by) answer = 0 return answer if divide_by == 0 while(num >= divide_by) num = num - divide_by answer = answer + 1 end answer end puts divide(10,0) Less

↳

Simpler version (assuming you are allowed to use multiplication), just compute the sign at the end and multiply: function divide(a, b){ if(b == 0) throw "Cannot divide by zero"; var remainder = Math.abs(a); var dividend = Math.abs(b); var result = 0; while(remainder >= dividend){ result++; remainder -= dividend; } if(result > 0 && a*b < 0) result *= -1; return result; } Less

↳

http://www.bearcave.com/software/divide.htm

Engineer - QCS Server Web Applications Development was asked...January 27, 2011

↳

return (( x!=0) && (x & (x -1) == 0)) a number which is power of two will have single 1 in binary representation ex. 16 00010000 x-1 will have pattern 00001111 hence x&(x-1) will always be 0 for power of two numbers. Need to check condition for x!=0 since 0 is not a power of two. Special case to handle. Less

↳

if you can figure this out inside an hour, congratulations this isnt something that should be in an interview to be honest the level of difficulty of the answer that algo came up with is at the level of an upper division course that has a proof of it written in wikipedia i honestly like the brute force solution Less

↳

Divide the number by 2, and repeat, until the result is a not an integer number (in this case is not a power of 2) or the result is 1 (in this case the number was a power of 2). Less

Web Development Engineer was asked...October 23, 2017

↳

const counter = (array, num) => { let a = numbers.indexOf(num); if (a >= 0) return numbers.lastIndexOf(num) - a + 1; return 0; } Less

↳

how to execute this code const counter = (array, num) => { let a = numbers.indexOf(num); if (a >= 0) return numbers.lastIndexOf(num) - a + 1; return 0; } Less

↳

const sort = (array, target) => { return array.filter(item => item==target).length; } Less

Web Development Engineer was asked...February 17, 2016

↳

script - var accordion = document.getElementsByClassName("accordion"); var i; for (i=0; i Less

↳

HTML - <div> <div>element number 1</div> <div>element number 2</div> <div>element number 3</div> <div>element number 4</div> <div>element number 5</div> </div> CSS - .accordion-element { display: inline-block; overflow: hidden; width: 20px; height: 20px; } .accordion-element.expanded { width: auto; } Javascript - function expandElement(elem) { var elementsToRemoveClassFrom = document.getElementsByClassName('expanded'); for (var i = 0; i < elementsToRemoveClassFrom.length; i++ ) { elementsToRemoveClassFrom[i].classList.remove('expanded') } elem.classList.add('expanded') } Less

↳

My answer was shortened by Glassdoor security mechanism. What's missing from my last answer is that for each HTML DIV element I added an "oncl1ck" attribute which called "expandElement(this)" Less

Web Development Engineer was asked...January 31, 2017

↳

Assuming it's a simple "equal" filter and the table is a 2-dimensional array like this- var table = [ ['name', 'occupation', 'age'], ['Roy1', 'Software Engineer', '29'], ['Roy2', 'Software Engineer', '26'] ]; I'd go with - function filterTable(table, param, value) { var paramIndex = table[0].indexOf(param); return table.reduce(function (acc, row) { if (row[paramIndex] === value) { acc.push(row); } return acc; }, []) } And then, for example for the input - filterTable(table, 'age', '29') I'd get back - [['Roy1', 'Software Engineer', '29']] Less

↳

var table = [ ['name', 'occupation', 'age'], ['Roy1', 'Software Engineer', '28'], ['Roy2', 'Software Engineer', '29'] ]; function filterTable(table, param, value) { var paramIndex = table[0].indexOf(param); return table.filter(item=>item[paramIndex]===value) } var res=filterTable(table, 'age', '29') console.log(abc) Less

↳

var table = [ ['name', 'occupation', 'age'], ['Roy1', 'Software Engineer', '29'], ['Roy2', 'Software Engineer', '26'] ]; let filterTable = (table, field, val) => { const col = table[0].indexOf(field); return table.filter(row => row[col] === val)[0]; } let res = filterTable(table, 'name', 'Roy2'); console.log(res); Less

Web Development Engineer was asked...March 11, 2012

↳

For a singly-linked list consiting of n linked nodes... i -2) { node[i+2].next <-- &node[i+1]; i = i - 1; } node[0].next <-- null; Less

↳

dave, the tricky answer given below is not acceptable in interview as well as in real programming. Please dont take these words as negative but try formulating solutions which are simple to understand and elegant. for example the invariants in above code and termination condition of -2 is not good. for example you can write -- Node* prev = &head; Node* curr = prev->next; while(curr) { Node* tmp = curr->next; curr->next = prev; prev=curr; curr = tmp; } return prev; Less

↳

This tutorial answers your question: http://youtu.be/LgapVjJYxqc

Engineer - QCS Server Web Applications Development was asked...January 27, 2011

↳

recursion ... defined "current=head" in the method so it doesn't changes ofcourse, even if I sent current.next in recursion... don't be nervous! Less

↳

Did not get this question? Could you please eleborate it more?