JS questions

interview questions

by leethelobster

HTML

customer obsession
ownership
invent and simplify
are right, a lot
curious
hire and develop the best
insist on highest standards
think big
bias for action
frugality
earn trust
dive deep
have backbone, disagree and commit
deliver results

JavaScript

/*-----------------------------------------------------------------------------
Write code on the whiteboard that could take user input and determine if it is a palindrome 
-----------------------------------------------------------------------------

function checkPalindrom(str) {
    return str == str.split('').reverse().join('');
}

console.log(checkPalindrom('racecar'));

-----------------------------------------------------------------------------
Write a function fib() that a takes an integer n and returns the nth fibonacci number. Let's say our fibonacci series is 0-indexed and starts with 0.
 *
 * i.e. 
 * fib(0) = 0
 * fib(1) = 1
 * fib(6) = 8
 * fib(36) = ??
 *
 * The Fibonacci series is a numerical series where each item is the sum of the two previous items. It starts off like this: 0,1,1,2,3,5,8,13,21...
-----------------------------------------------------------------------------

var fibonacci = function() {
	var memo = [0,1];
  var fib = function(n) {
    if (typeof result === 'undefined') {
      memo[n] = fib(n-2) + fib(n-1);
    }
    return memo[n];
  }
  return fib;
}();

-----------------------------------------------------------------------------
Take two arrays and compare them to find duplicates. Only list each duplicate once.
-----------------------------------------------------------------------------

var array1 = [1,2,3,4,5,6,7];
var array2 = [2,3,4,324,5436,15];

function detectDupe(arr1, arr2) {
	var tmp = [];
	arr1.forEach(function(item, idx, arr1) {
    if (arr2.indexOf(item) !== -1) {
      tmp.push(item);
    }
  });
  return tmp;
}

console.log(detectDupe(array1, array2));

-----------------------------------------------------------------------------
Make this work: duplicate([1,2,3,4,5]); // [1,2,3,4,5,1,2,3,4,5]
-----------------------------------------------------------------------------

var given = [1,2,3,4,5];

function duplicate(arr) {
	var tmp = arr;
  arr.forEach(function(item, idx, arr) {
  	tmp.push(item);
  });
 ...