Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanoats/fac564a3f4845ee08063 to your computer and use it in GitHub Desktop.
Save ivanoats/fac564a3f4845ee08063 to your computer and use it in GitHub Desktop.
Code Fellows dev bootcamp application question
// QUESTION
// What does the following JavaScript code do?
var
obj1 = {value: 1},
obj2 = {value: 2},
obj3 = {value: 3};
var ValueCollect = function() {
var values = [];
var operation = function(obj) {
if (obj) {
values.push(obj.value);
return values;
}
else {
return values;
}
};
};
var accumulator = ValueCollect();
accumulator(obj1);
accumulator(obj2);
// POSSIBLE ANSWERS (multiple choice)
// (A) The code will work as designed by collecting all object values in values array
// (B) The code will hold only one object value at any given time
// (C) The code will not work because of what Tony Hoare called a billion dollar mistake
// (D) The code will not work because operation function is incomplete
// (E) The code will work only if ValueCollect function is declared before declaring obj1 and obj2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment