Last active
October 5, 2015 23:30
-
-
Save emmettnicholas/4191c5344a69f9e4668d to your computer and use it in GitHub Desktop.
Code Fellows dev bootcamp application question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 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.
@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
Lol, getting there
FYI, thanks for the feedback. The answers have been reworded.
@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
Not hiring anyone from CodeFellows anytime soon