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.
A function that takes a list of numbers and returns the product obtained by multiplying them all together. Note the product of no numbers is 1, a.k.a. the “multiplicative identity”.
A function that takes a single non-negative integer argument, n, and returns the sum of the squares of the numbers from 0 to n.
A function that takes a non-negative integer argument and returns the nth Lucas number. A Lucas number is like a Fibonacci number except the sequence starts with 2 and 1 rather than 0 and 1. (I.e. lucas(0) is 2). Subsequent Lucas numbers are the sum of the two previous Lucas numbers.
A function that takes an array of numbers and return true if they are sorted in ascending order and false otherwise. An array is in ascending order if each element is less than or equal to the next element.
A function that takes an array of numbers and return true if they are sorted in descending order and false otherwise. An array is in descending order if each element is greater than or equal to the next element.
["A function that takes a single argument that is either a number
(which you can test with the provided isNumber
function)
or an array containing either other numbers or more arrays. Return the
sum of all the numbers.","Hint: while these are arrays, the recursion
is more of a tree recursion."]
A function that takes two arguments. The first is like the argument to sumNested and the second is a number. Return true if the second argument appears anywhere in the nested arrays in the first argument.
["(Note: this is an extra challenging problem.) A function that
takes an argument representing a mathematical expression and returns
its value. If the argument is a number, the value is that number.
Otherwise the argument will be an object with three properties:
op
, left
, and right
. The value
of the op
property will be one of the strings
'+'
, '-'
, '*'
, or
'/'
, indicating the mathematical operation. The
left
and right
properties will be
expressions, again either a number or an object representing an
expression.","To evaluate an expression object, evaluate its left and
right sides and then apply the indicated mathematical operation to the
results. For example the expression object:","{ op: '+', left: 10, right: { op: '*', left: 2, right: 3 } }
","represents 10 + 2 * 3 and thus should evaluate to 16."]
For all the functions in this assignment I want you to write a recursive function. As in the second problem set, some of these functions are not ones that you'd naturally write recursively. Others, however, are.
As in the previous assignment, for functions the recurse on arrays,
you may want to use the fact that s.slice(1)
returns an
array consisting of all but the first element of xs
. E.g.
[2, 3, 5, 7, 11].slice(1)
evaluates to a new array
[3, 5, 7, 11]
. Similarly you can recurse on strings using
s.substring(1)
to get the string containing all but the
first character of s
.
This problem set contains a couple problems that ask you to recurse on
arrays the represent trees. I.e. instead of building a tree out of
objects we build a tree out of nested arrays. In this kind of
recursion, you'll usually have a double recursion, one recursing on
the 0th element of the array and the other recurling on the rest (i.e.
the slice(1)
) of the array.