Front-end engineer interview questions

var Player = function() {  
  this.playCount = 0;
  this.play = function() {
    // Do some actual work
    this.playCount++;
  }
}

var player = new Player();

// If we want to reset the play count, we could access it directly:

player.playCount = 0;

// I would argue this is not a safe pattern. Why not? What could we do better?
function multiply(multiple) {  
  // Your code here
}

// Fill out the multiply function such that the code below works
var double = multiply(2);  
double(2) // Should return 4  
function Tree(value) {  
  this.value = value;
  this.left = null;
  this.right = null;
}

Tree.prototype.insert = function(value) {

  if (value < this.value) {
    if (this.left) {
      this.left.insert(value);
    } else {
      this.left = new Tree(value);
    }
  }

  if (value > this.value) {
    if (this.right) {
      this.right.insert(value);
    } else {
      this.right = new Tree(value)
    }
  }

}

// What is the best and worst case time complexity of insert

// Should return whether a tree contains 'value'
Tree.prototype.contains = function(value) {  
  // Your code here
}
var i, person, age;  
var people = [  
  { name: 'Pinky', birthDate: 1986 },
  { name: 'Brain', birthDate: 1995 },
  { name: 'Larry', birthDate: 1997 }
];
var year = 2015;  
var overTwentyone = [];

for (i = 0; i < people.length; i++) {  
  person = people[i];
  age = year - person.birthDate;
  person.age = age;
  if (age >= 21) overTwentyone.push(person);
}

// Can we replace this 'for' loop with something more functional?
// What are the pros and cons of this approach?