This assessment consists of functions you need to write involving primarily arrays, objects, and 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.)
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 area that takes a single
argument which will be an object with width
and height properties representing the dimensions of a
rectangle and returns the area of the rectangle as a number.
Write a function named higherPaid that takes two
arguments, each an object representing an employee. The employee
objects each have a salary property and the function
should return the object representing the employee with the higher
salary.
Write a function named isSamePoint that takes two point
objects as arguments, each with x and y
properties, and returns a boolean indicating whether the two objects
represent the same x, y coordinate.
Write a function named totalWithTip that takes two
arguments, an object with a property subtotal and a
number between 0 and 1.0 representing the percentage tip, e.g. 20%
tip would be 0.2. Return a new object that has three
properties, subtotal with the same value as the
argument object, tip which is the tip computed from the
subtotal and the given percentage, and total which is
the total with the tip.
Write a function isWinner that takes an object with
a score property and returns true if the score is over
100 and false otherwise.
Write a function updateWins that takes an array of
objects each with a score property and
a wins property and updates each object by
incrementing wins by one if the object is a winner
according to the isWinner function you just wrote.
After updating the objects, updateWins should
return undefined.
Write a function bigWinners that takes an array of objects each with
score and wins properties and returns an
array containing the elements of the argument array
whose wins property is over 10.
Write a function named fillTimesTable that takes a
single n-by-n 2D array as an argument. That is, the
argument will be an array with n elements each of which is an
array of n elements. The inner arrays will initially be
filled with zeros. The function should replace each zero with the
products from 1 × 1 at table[0][0] and n
× n at table[n - 1][n - 1] and
return undefined (Note, n itself is not an
argument to the function.)
For instance, if called with the empty table:
[[0 , 0, 0], [0, 0, 0], [0, 0, 0]]
it should leave the table in this state:
[[1, 2, 3], [2, 4, 6], [3, 6, 9]]
Write a function sums that takes a single
number, n and returns an array with n + 1
numbers in it such that each element of the array is the sum of the
index of that element and the preceeding indices. (The zeroth
element should have the value 0.) For example sums(5)
should return [0, 1, 3, 6, 10, 15]. The third
item, 3 is 3 because it's at index 2 + the preceeding
value of 1.
Write a function rule110 that takes an array of
arbitrary length containing only 0s and 1s as its argument and
returns a new array of the same length filled according to the
following somewhat complicated rules:
For each index, i, the value at i in the
new array is determined by the three values in the original array
at i - 1 (the left value), at i (the
center value), and at i + 1 (the right value).
When i is 0 use 0 for the left value and
when i is the last index in the array, use 0 for the
right value.
The ith value of the result array will be 0 in three
cases: when the left, center, and right values are all 0 or the two
cases when the left value is 1 and the center and right values are
the same, i.e. both 0s or both 1s. In all other cases,
the ith element in the result is 1.