Skip to content

RahmatSaeedi/focals

Repository files navigation

Focals

Daily challenges from Light House Labs Web Development Bootcamp.

Week 3

Vampr

An exercise that implements some simple, non-recursive tree node methods as an introduction to Trees data architecture.

Vampire class provides lineage information, such as

  • a vampire's creator.
  • number of vampires has a vampire created.
  • number of vampires away from the original vampire a vampire is.
  • compares seniority two vampires. (Who is closer to the original vampire)
  • closest common ancestor of two vampires.

Methods and properties:

Here are some of the methods / properties of this calss.

  • numberOfOffsprings() : Returns the total number of vampires created by that vampire
  • youthfulness() : Returns the number of vampires to the original vampire
  • isMoreSeniorThan( someVampire ) : Returns true if this vampire is more senior than the other vampire (someVampire).
  • closestCommonAncestor( someVampire ) : Returns the closest common ancestor of two vampires.
  • totalNumberOfDescendants() : Counts the total number of descendants that this vampire has
  • vampireWithName(name) : Returns the vampire object with that name, or null if no descendant-vampire with that name exists

Mocha Chai Test

To run the test, issue the following commad npm test -- test/vampr.js

The output should be simillar to thee following:

> mocha "test/vampr.js"



  Vampire
    addOffspring
      √ should get added to offsprings
      √ should add parent as the creator
    numberOfOffsprings
      √ should get the correct number of offsprings
    youthfulness
      √ root should be 0 from original
      √ offspring1 should be 1 from original
      √ offspring2 should be 2 from original
      √ offspring3 should be 3 from original
      √ offspring4 should be 4 from original
      √ offspring5 should be 5 from original
    isMoreSeniorThan
      √ should return true when called on root vampire
      √ should return false when called with root vampire
      √ should return true when a vampire is more senior
      √ should return false when a vampire is not more senior
    closestCommonAncestor
      √ should be the root vampire for any vampire and the root vampire
      √ should be the root vampire for first two offspring
      √ should be offspring 3 for offspring 4 and 7
      √ should be that vampire if same vampire is used
      √ should be the more senior vampire if a direct ancestor is used
      √ should be root for offspring 8 and offspring 7
    totalNumberOfDescendants
      √ should return 8 for the rootVampire
      √ should return 0 for the vamprire without descendants
    vampireWithName
      √ Returns 'null' if vampire name does not exists.
      √ Returns correct vampire for descendant 'offspring1'
      √ Returns correct vampire for descendant 'offspring2'
      √ Returns correct vampire for descendant 'offspring3'
      √ Returns correct vampire for descendant 'offspring4'
      √ Returns correct vampire for descendant 'offspring5'
      √ Returns correct vampire for descendant 'offspring6'
      √ Returns correct vampire for descendant 'offspring7'
      √ Returns correct vampire for descendant 'offspring8'

  30 passing (16ms)

Example Lineage Info:

vampr linage

A class, Employee, that creates an organisational tree, with the following properties:

  • Employee.name: a string storing employee's name
  • Employee.title: a string storing employee's title
  • Employee.salary: a number storing employee's salary
  • Employee.boss: an object, pointing to the parent node, representing employee's supervisor
  • Employee.subordinates: an array of objects, representing Employee's subordinates
  • Employee.addSubordinates(sub): adds sub as a subordinate to Employee.subordinates array. sub is an instance of Employee class.
  • Employee.numberOfPeopleToCEO: returns the number of people between the employee and the CEO.
  • Employee.sameBoss(someone): checks whether someone and the employee share the same buss.

An app for space enthusiasts who are interested in spotting the International Space Station (ISS). The space station is visible because it reflects sunlight. However, unlike the Moon, the space station isn't bright enough to be seen during the day. It can only be seen when it is dawn or dusk at your location.

Logs the result to console.log in a human-readable format. Sample Output

Orchestrates multiple API requests in order to determine the next 5 upcoming ISS fly overs for the user's current location.

  • Input:
    • A callback with an error or results.
  • Returns (via Callback):
    • An error, if any (nullable)
    • The fly-over times as an array (null if error):
      [ { risetime: <number>, duration: <number> }, ... ]
    • Location used for the ISS info lookup:

Simillar to iss.js and index.js but implemented using Promises.

Processes argv input and passes cat-breeds to breedFetcher.js to obtain its description, and to prints a short description of the breed.

> node index Siberian Chartreux
# Upon a successful fetch, it may return:
:'

Siberian Info:
The Siberians dog like temperament and affection makes the ideal lap cat and will live quite happily indoors. Very agile and powerful, the Siberian cat can easily leap and reach high places, including the tops of refrigerators and even doors.

Chartreux Info:
The Chartreux is generally silent but communicative. Short play sessions, mixed with naps and meals are their perfect day. Whilst appreciating any attention you give them, they are not demanding, content instead to follow you around devotedly, sleep on your bed and snuggle with you if you’re not feeling well.
'

Returns queried details about a cat breeds. Users can provide any breed name, causing the application to fetch the information from thecatapi.com.

const fetchBreedDescription = require('./breedFetcher');
fetchBreedDescription('Siberian', callback);
// where possible callbacks:  callback(null, [STRING])

To test the program run npx mocha

Week 2

A class with getters and setters to manipulate properties of a pizza.

An command-line Todo List app, built to learn OOP.

A small command line node app which takes a URL and a local file path, as command-line arguments, and downloads the resource to the specified path.

> node fetcher.js http://www.example.com/ ./index.html
Downloaded and saved 3261 bytes to ./index.html

Uses request pacakge, installable via npm install request, to fetch a page from example.com.

Makes an example HTTP/1.1 request to example.com:80/ and logs the response.

Server - Client model

server.js contains the bare minimum to start a server on port 8080. It accept multiple connections and send a welcome message to them. client.js connects to server and sends greeting message.

Simillar to a survey, asks a seriers of questions in a specific order, and generates a narrative paragraph.

Paragraph construct

`${name} like to play ${sport}. Sometimes ${name} eats ${food} food, because ${name} likes that very much.
${name} is friend with ${someone}. They like to travel to ${vacationSpot}. In the past, ${name} visited ${placesVisited}.`

Interactive timer behavior:

  • user can press b and it beeps right away
  • user can press 1 to 9 and
    • console.logs "setting timer for {x} seconds..."
    • beeps after {x} seconds passed
  • ctrl + c logs "Thanks for using", and terminates the program

Outputs . for each stdin character recieved. On ctrl + c input, the program terminates.

Based on the argv inputs, the timer beeps after a specified duration. Example > node timer 7 8 12 would ring the system bell after 7, 8, and 12 seconds has passed

animates a spinner on the console, (character |/-|/-| in that order), as though it is spinning

spinner

Hello there from the other side of the monitor.

> node typewriter
Hello there from the other side of the monitor
# displayed 1 character at a time, 50 milliseconds apart.
> node hello_timeout
4311o     # printed 1 seconds printed after the file is run
th3r3     # printed 2 seconds printed after the file is run
w0r1d     # printed 3 seconds printed after the file is run

Same as library.js but uses methods to manage the library.

library.js is a program that manages music playlists using objects and arrays.

  • printPlaylists : prints a list of all playlists, in the form:

    {playlist ID}: {playlist name} - {#} tracks
    p01: Coding Music - 2 tracks
    
  • printTracks : Prints a list of all tracks, using the following format

    {trackID}: {track name} by {artist} ({album})
    t01: Code Monkey by Jonathan Coulton (Thing a Week Three)
    
  • printTrack : Simillar to printTracks, but prints info on a single

  • printPlaylist : Prints a list of tracks for a given playlist, using the following format:

    printPlaylist('p01')
    // p01: Coding Music - 2 tracks
    // t01: Code Monkey by Jonathan Coulton (Thing a Week Three)
    // t02: Model View Controller by James Dempsey (WWDC 2003)
  • addTrackToPlaylist : Adds an existing track to an existing playlist

  • addTrack : Adds a track to the library

  • addPlaylist : Adds a playlist to the library

  • printSearchResults : Given a query string string, prints a list of tracks where the name, artist or album contains the query string (case insensitive)

Week 1

This file sums the input argumets

> node sum 1 2
3

> node sum 100 20 30 50
200

A function such that it takes 2 input and prints a suggestion. (Boolean representing state of hunger, & number representing time in minutes to spare)

Output:

  I'm hungry and I have 20 minutes for lunch.
  Try to eat at a nearby food store
  ---
  I'm hungry and I have 50 minutes for lunch.
  You are in the bootcamp, are you sure you got more than 30 minute?!
  ---
  I'm not hungry and I have 30 minutes for lunch.
  Go back to work!
  ---
  I'm hungry and I have 15 minutes for lunch.
  Pick something up and eat in the lab

Reverses the order of characters in a string. String are pssed via bash argv arguments.

> node reverse.js hello goodbye
olleh
eybdoog

Converts each input argument srings to pig latin (using simplified rules), then puts the translated words together into one sentence, and logges it to the console.

> node pig-latin Hi my name is John
ihay mymyay amenay isyay ohnjay
> node pig-latin this is all just gibberish
isthay isyay allyay ustjay ibberishgay

concepts.js

Joins an array of strings.

Given

const conceptList = ["gists", "types", "operators", "iteration", "problem solving"];
console.log(conceptList);
> node concepts
Today I learned about gists, types, operators, iteration, problem solving.

Takes a command line argument (a password) and obfuscates it by following a few rules.

  • Obfuscation Rules
    • Every "a" in the string should be replaced with a "4".
    • Every "e" in the string should be replaced with a "3".
    • Every "o" (oh) in the string should be replaced with a "0" (zero).
    • Every "l" (el) in the string should be replaced with a "1" (one).
> node password.js password
p4ssw0rd

> node password.js abracadabra
4br4c4d4br4

> node password.js audaciously
4ud4ci0us1y

Takes a single parameter (a number) from the command line and rolls that many six-sided dice.

Example:

> node dice-roller 3
Rolled 3 dice: 2, 6, 5

> node dice-roller 5 10
Rolled 5 dice: 6, 5, 5, 1, 1
Rolled 10 dice: 6, 2, 6, 1, 2, 5, 4, 5, 1, 4

Averages a given array of numbers.

Reverse the characters of words passed via command line arguments.

> node reverse Hi there. How are you?
iH .ereht woH era ?uoy

> node reverse I am good. Thank you for asking.
I ma .doog knahT uoy rof .gniksa

Checks if a string or sentence a palindrome.

Examples:

> node isPalindrome "a santa at NASA"
true

> node isPalindrome "racecar"
true

> node isPalindrome "foo"
false

Sums 1 to n recursively.

// Example
sumRecursively(4);
// Returns: 10

Prints the content of a nested array.

const myArray = [1, [[[[[2]]]]], 3, [4, 5, [6, [7]], 8, 9], 10];
printNestedArrays(myArray);
/* Returns
1
2
3
4
5
6
7
8
9
10
*/

Sums fromN to toN recursively. Includes the end points. Assumes integer inputes, with fromN smaller than toN.

// Example
sumRecursivelyFromTo(3, 7);
// Returns: 25

Sums all the numbers in a nested array, recursively.

Input Output
[1, 2, 3, 4, 5] 15
[[1, 2, [[3], 4]], 5, []] 15
[[[[[[[[[[[[[1]]]]]]]]]]]]] 1

About

Light House Labs Web Development Bootcamp daily challanges/Focals

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published