Welcome to BHS Computer Science. If you are a student in the class, the first thing you need to do (and which we should have done in class) is set up your GitHub account.
Once you have a GitHub account, click “Log in to GitHub” below to proceed. Or you can click “Use anonymously” to play with the environment but you will not be able to save your work or submit assignments. (You can always log in later by clicking the at the top of the page.)
If you don’t have a GitHub account yet, please create one and then log in here for further instructions.
Congratulations! You have successfully connected this app to GitHub. However you are not yet a member of the GitHub organization for this class, something Mr. Seibel needs to set up for you.
This is your GitHub profile URL:
Click the clipboard icon to copy it and then submit it at this form so he can add you.
Congratulations! You have successfully connected this app to GitHub. And it looks like you have an invitation to join the GitHub organization for this class. You need to accept that invitation before you can proceed. The invite should be sent to whatever email you used when you created your GitHub account.
I see you are logged into GitHub and a member of the berkeley-high-cs GitHub organization. However there seems to have been some problem finishing the setup for your account. Please let Mr. Seibel know.
This is a tool for the BHS Computer Science class at Berkeley High School. It is intended to provide a simple environment for experimenting with Javascript without all the complexities of a full development environment such as ReplIt or Glitch which we may use later in the year.
It is also designed to take advantage of the browser’s ability to run Javascript natively. It does not need access to a server to run code making in extremely responsive even if the Wifi is flaking out.
Finally, under the covers it is saving work to a GitHub repository in a very simplified workflow that does not depend on immediately learning any git commands. Code written in this environment for each assignment is saved to a directory and branch specific to that assignment each time it is saved. Thus when the assignment is done, it is easy to go to GitHub and create a PR containing just the work on that assignment which can then be commented on and worked on further before it is turned in and merged to main.
You're all set! You don't need to worry about this yet but we have successfully created a GitHub repository for your work:
You can get to it any time by clicking on your GitHub username at the top-right of the screen.
This assessment consists of recursive functions you need to write. This is an closed book assessment.
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.
Write a recursive function named factorial
that
takes a single non-negative integer argument and returns the nth
factorial number which is defined as the product of the integers
from 0 to N, inclusive except that the 0th factorial, i.e.
factorial(0)
, is 1.
Write a recursive function named fibonacci
that
computes the nth element of the Fibonacci sequence, 0, 1, 1, 2,
3, 5, 8, etc. After the first two items, i.e.
fibonacci(0)
which is 0 and
fibonacci(1)
which is 1, each item in the sequence
is the sum of the two previous items.
Write a recursive function named sumSquares
that
takes a single non-negative integer argument, n, and
returns the sum of the squares of the numbers from 0 to
n, inclusive.
Write a recursive function named maximum
that takes
an array of numbers and returns the maximum value in the array.
If the array is empty, it should return the special value
-Infinity
.
Write a recursive function named treeMap
that takes
two arguments, a tree and a function. Trees are either objects
with left
and right
properties or leaf
values that can be anything. The function isLeaf
,
which is already defined for you in the starter code, will tell
you whether a given value is a leaf. The function should return
a new tree with the same structure as the original but with each
leaf replaced with the result of calling the passed in function
with the old leaf value as an argument. For instance:
treeMap({left: 10, right: { left: 2, right: 3 } }, (x) => x *
2)
should return:
{ left: 20, right: { left: 4, right: 6 } }
Write a recursive function named
sumPrimesBelow
that takes a single integer argument
greater than 1 and returns the sum of the prime numbers less
than or equal to that argument. For instance
sumPrimesBelow(10)
should return 17. You should use
the function isPrime
, which has been defined for
you in the starter code, to test if a given number is prime.
Write a recursive function named nvwls
(short for
noVowels) that takes a string as an argument and returns a
string with all the same characters as the original but with all
vowels (a, e, i, o, and u) removed.
Write a recursive function named caesar
that takes
a string and a key (which happens to be a number) and returns
the string encoded by rotating each character using the
rotate
function, which has been defined for you in
the starter code and which rotates a character around the
alphabet based on the key
argument. As simple test
of whether this is working applying caesar
twice
with the key 13 should get you back to where you started, e.g.:
caesar(caesar('any string', 13), 13) === 'any string'
Write a recursive function named toList
that takes
a single array argument and returns an object representation of
the array in the following format, called a list. (Note: in this
context a “list” is not an array even though sometimes in
Javascript we’ll informally call an array a list.)
null
first
and rest
.
first
property is the first
item of the array.
rest
property is a list
containin the remaining elements of the array.
For instance, the array [1, 2, 3]
would be
represented as:
{ first: 1, rest: { first: 2, rest: { first: 3, rest: null }
} }
Write a recursive function named map
that takes two
arguments, a list as returned by the
toList
function from the previous question and a
function, and returns a new list represented in the same way
with each first
value replaced with the result of
passing the original first
value to the function argument.
For instance:
map({ first: 1, rest: { first: 2, rest: { first: 3, rest:
null } } }, (n) => n * 10)
should return:
{ first: 10, rest: { first: 20, rest: { first: 30, rest: null
} } }