extends
, super
)map
& reduce
describe
, it
, and expect
functionsYou will not have to write code to make HTTP requests in JavaScript.
User-Agent
that contains a description of the browser (or command line program like curl) that is making the requestGET
request vs. a POST
request?Day
date
, a JS Date
objecttrue
if M-F, false
otherwiseDay
called Holiday
isTechtonicaDay
should return true
regardless of day of weekCreate an array of these objects to represent the week beginning with Sunday, 16 Feburary 2020.
const weekendDay = new Day('2020-02-16');
sun.isTechtonicaDay();
// => false
const weekDay = new Day('2020-02-17');
weekDay.isTechtonicaDay();
// => true
const holiday = new Holiday('2020-02-17');
holiday.isTechtonicaDay();
// => false
Write a function that creates another function called createPlucker
that is very similar to our extractProp
method from the previous assessment but that always retrieves the same property name.
function createPlucker(propName) {
// returns a function that takes in an array and
// returns an array of the values of each item's property named propName
}
const lengthPlucker = createPlucker('length');
const array = ['a', 'aa', 'aaa'];
lengthPlucker(array);
// => [1, 2, 3]
const namePlucker = createPlucker('name');
const objsWithNames = [
{ name: 'Osito', age: 14 },
{ name: 'Bella', age: 8 }
];
namePlucker(objsWithNames);
// => ['Osito', 'Bella']
Given classes representing files and folders in a filesystem.
/**
* Base class for any item on disk.
* Every item (folder or file) has a name
*/
class FilesystemItem {
constructor(name) {
this.name = name;
}
isFile() {
return false;
}
}
class Folder extends FilesystemItem {
constructor(name, parentFolder) {
super(name);
this.contents = [];
if (parentFolder) {
parentFolder.addItem(this);
}
}
getContents() {
return this.contents;
}
addItem(fileOrFolder) {
this.contents.push(fileOrFolder);
}
containsFile(name) {
// TODO: implement
}
}
class File extends FilesystemItem {
constructor(name, parentFolder) {
super(name);
parentFolder.addItem(this);
}
isFile() {
return true;
}
}
const homeFolder = new Folder('home');
const desktopFolder = new Folder('Desktop', homeFolder);
const dotProfile = new File('.profile', homeFolder);
const raccoonPic = new File('raccoon.jpg', desktopFolder);
homeFolder.containsFile('raccoon.jpg') // => true (since it's in desktop folder, which is part of home folder)
homeFolder.containsFile('nonexistent') // => false
desktopFolder.containsFile('raccoon.jpg') // => true
desktopFolder.containsFile('.profile') // => false (since it's not in desktop, only its parent)
Write a function containsFileNamed(folder, name)
containsFileNamed(home, '.profile');
// => true
containsFileNamed(desktop, '.profile');
// => false
containsFileNamed(desktop, 'raccoon.jpg');
// => true
containsFileNamed(home, 'Desktop');
// => false (because Desktop is a folder, not a file)
containsFileNamed(home, 'raccoon.jpg');
// => true
Write Jasmine test cases for the function below. Think of all the possible cases you might need to test.
function calculateAge(birthDate) {
const msDiff = Date.now() - birthDate;
const ageDate = new Date(msDiff);
return Math.abs(ageDate.getFullYear() - 1970);
}
describe('calculateAge()', function() {
it('should do something', function() {
expect(true).toBe(true);
});
});