saymedia

0.2.0 • Public • Published

Say Media Coding challenge

Jesse Mull
04/11/2017

Overview

My solution to the Say Media coding challenge uses simple angular boilerplate and a dynamic single page web application. The user can navigate and interact with the challenges using the tabs at the top of the page. All forms in the application validate user input. Starting the application fires up an http server listening on http://localhost:8000/

Installation

Installation option 1 - NPM

This coding challenge is published as an NPM module. To install and fire up the application:

npm init
npm install saymedia
cd node_modules/saymedia
npm start

Navigate a browser to http://localhost:8000/.

Installation option 2 - GitHub

This coding challenge is also hosted on my github account. To install and fire up the application:

git clone https://github.com/jessemull/SayMedia
cd SayMedia
bower install
npm start

Navigate a browser to http://localhost:8000/.

Installation option 3 - Google Drive

I sent a link in my reply e-mail to a Google Drive folder containing a zip file with the solution.

Challenge 1: Primes

This is an implementation in Javascript of the Sieve of Eratosthenes. For our purposes here the valid range for the number of primes to count is 1 - 10,000 but the algorithm can print out many more primes efficiently. The output lists the number of primes to count and prints an array holding all the prime numbers. See the wiki page for the pseudo code.

Challenge 2: Block Quotes

Here the user can toggle back and forth between block quotes and paragraphs in a content editable div element. Angular wraps the window and document objects in an injectable service but this algorithm would also work with vanilla Javascript. The inner text from the div element is retrieved. The text is split on new lines. The editable div is cleared and each new block quote elements for each paragraph are appended as children of the editable div element.

Challenge 3: Sum Pairs

For challenge three the user can input a list of comma separated values and a target or generate a random array and target. To process the list of values the text from the input field is split on a comma then stored in an array. The find pairs algorithm does a single pass of the values. For each value the function checks if the matching number for the pair has already been stored in a set. If it is the pair is added to the output array. If complimentary number is missing the value is added to the set. The output prints the list of input values and the pairs whose sum is equal to the target.

Challenge 4: Cargo Allocation

The solution to this challenge uses a car service to create an output string holding the allocation. The car service holds a car object that contains the type of car, the capacity of the car and the quantity of cars. New car objects are instantiated in the module controller rather than the service so that it can be recycled for use by any module. The allocate method takes a list of car objects and a weight, iterates over the array of cars and continues to add tonnage to each car until all cargo has been allocated or the allocation space runs out. The allocation string is then displayed as output in the challenge four view.

Readme

Keywords

none

Package Sidebar

Install

npm i saymedia

Weekly Downloads

1

Version

0.2.0

License

MIT

Last publish

Collaborators

  • jesselylemull