What is the type of this JavaScript object?
const point = { x: 3, y: 4 }
point
object
Point
Which of these prints all elements of an array?
for (let i = 0; i < arr.length; i++) console.log(arr[i])
for (const element of arr) console.log(element)
for (const key in arr) console.log(arr[key])
Consider the function
function larger(x, y) { if (x > y) return x }What is the result of the function call
const result = larger('3', '20')
20
'20'
'3'
undefined
lab15
subdirectory of your personal repo, the other submits a file report.txt
in the lab15
subdirectory of your personal repo.sudo apt install nodejs npm
sudo npm install standard --global sudo npm install jest --global
console.log
statements to lab15/graph.js
that logs your objects. Run the file:
cd ~/cs151/lab15 node lab15.js
'use strict'to the top of your JavaScript file, before the variable declarations. We always want to run strict mode.
findNode
that works like Graph.findNode
. Pass the graph object and the point (in some way, either as an object or as two values) to the function. Return the node. For now, just check if the location of the node and the point are exactly the same--you don't know yet how to invoke contains
on a node.console.log
statement to lab15/graph.js
that calls your function and prints the result.standardin the
lab15
directory.neighbors
that, given a graph and a node, yields an array of neighboring nodes. (You need to know how to add something to the end of a JS array. arr.push(obj)
does that—it's like ArrayList.add
in Java.)