This assessment consists of functions you need to write exercising your ability to use Javascript’s basic control constructs. It is a closed book assessment. You should stay on this tab until you are done and there should be no talking. This assessment is about how much you understand. There are no automatic tests but you can use the REPL to test things yourself.
You can move through the questions with the arrows at the upper right next
to the 1 of indicator so if you're not
sure how to write one function move on to another one and come back if you
have time at the end. I want to see how much you do know. Note: you
can also click on thingsLikeThis
in these instructions and
the questions to copy them to the clipboard to avoid spelling mistakes.
(I.e. click to copy and then ⌘-v to paste wherever you want.)
Note The starter code contains a lot of functions. You do not need to worry about how those functions work and don’t need to change them. Write your code below them.
When you are done, please click on your Github username above and
submit a GitHub pull request of the branch
and request me as a reviewer. Doing this correctly is part of the
assessment. If you are unsure how to request a review, please ask for
help!
Write a function named logIfOk
that takes a single
argument that can be passed to the function isOk
provided in the starter code to get a boolean indicating whether the
value is “okay”. If the value is okay according to isOk
you should call the provided log
function, passing the
value so it can be logged. Note: you do not need to
write isOk
or log
but you can adapt the
simple implementations in the starter code if you’d like to test
your code.
Write a function named firstOk
that takes a numeric
argument and returns the first integer greater than or equal to zero
and less than the argument that is okay according to
the isOk
function. If none of the numbers in the range
are okay, it should return undefined
.
Write a function named timeToLeet
that repeatedly
generates random numbers with the provided random10k()
function and returns the number of numbers generated that were not
leet, according to the provided isLeet
function, before
a leet number was generated. (Thus if the very first number
generated is leet, it should return 0. If the 101st number generated
was leet, then it should return 100.)
Write a function named classify
that takes an arbitrary
value as its single argument and calls one of the provided
functions recordOk
or recordNotOk
with the
value, the former if the value is okay according isOk
and the latter otherwise.
Write a function named threewayClassify
that takes an
arbitrary value as its single argument and calls one of the three
provided functions recordOk
, recordMeh
,
or recordNotOk
with the value. It should
call recordOk
if the value is okay according
to isOk
, recordMeh
if the value is meh
according to isMeh
, and recordNotOk
otherwise.
Write a function named sumOfSquares
that takes a single
numeric argument and returns the sum of the squares of the positive
integers less than the argument. For
instance sumOfSquares(10)
should
return 285
.
Write a function named pairs
that takes a single
numeric argument and calls the provided pair
function
with every possible pair of numbers made up of two numbers each in
the range from 1 to the argument. For
instance, pairs(3)
would result in calls
to pair
with the pairs (1, 1)
, (1,
2)
, (2, 1)
, and (2, 2)
. Note that
order matters so (1, 2)
and (2, 1)
are
different pairs. Also note: pair
takes two arguments so you
just need to pass the two numbers; you do not need to do anything
else to create a pair.