Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save emmettnicholas/4191c5344a69f9e4668d to your computer and use it in GitHub Desktop.
Save emmettnicholas/4191c5344a69f9e4668d 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 obj1 and obj2 are declared outside the ValueCollect function and will be treated as undefined
// (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
@llenodo
Copy link

llenodo commented Oct 1, 2015

Not hiring anyone from CodeFellows anytime soon

@ayax79
Copy link

ayax79 commented Oct 3, 2015

@llenodo The point is that is is intentionally borked... Did you bother reading the possible answers section? Javascript isn't even my primary language and I could figure that out.

@ayax79
Copy link

ayax79 commented Oct 3, 2015

@ivanoats Is this better? ;)

data ValueObj = ValueObj { objVal :: Int } deriving (Show)

main = do
  let obj1 = ValueObj {objVal=1}
      obj2 = ValueObj {objVal=2}
      obj3 = ValueObj {objVal=3}
      result = map (\x -> objVal x) [obj1, obj2, obj3]
  putStrLn $ show result

@ivanoats
Copy link

ivanoats commented Oct 3, 2015

Lol, getting there

@ivanoats
Copy link

ivanoats commented Oct 5, 2015

FYI, thanks for the feedback. The answers have been reworded.

@emmettnicholas
Copy link
Author

@ayax79 ... so which answer would you choose?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment