Coding Challenge - Eyewire

Note: My answers are in blue

SQL:

Given the following SQL tables:
logbook (id, aircraftid, departure, arrival, pilotname, comment)
aircraft (id, name)
installedpart (id, aircraftid, partid, installationdate)
part (id, parttypeid, serial)
parttype (id, name, manufacturer)
inspections (id, mechanicname, partid, comments, recertified, date)

An aircraft named the “Cerulean Sky” recently had to be landed in an emergency
condition for an unknown reason. Thankfully everyone was okay, but the forensic
investigators would like to pull the following records:

Notes: 

1. assume departure, arrival, and recertified attributes are dates and not other text fields
2. assume inspection date is different from part recertified date.
3. assume recertification must have taken place 7 days before flight
4. assume departure of flight in question was logged in the logbook before query was run
5. the following are sketches of solid starting points for the queries. I would not write the queries as such without testing smaller subqueries against the database or a subsample of the database to verify the logic (unless, of course the database were not available - then I would spend more time than I have here). I would especially verify the function calls or look them up in a reference if the specific database software version had a good reference of functions). I am very efficient with SQL queries and developed my large data analysis skills on a medicaid claims database for the year 1992 (for the whole US) - helping to write fraud queries when my employer borrowed a Thinking Machine from MIT's Kendall Square spin-off. The work would have taken significantly less time had I had the database available to me (I would have given an SQL export of relevant records in the database to those I wanted to test if I required more than sketches). I spent 75 minutes before stopping. 

1) Were there any parts that had failed to be re-certified on the date of its most recent flight?

SELECT inspection.partid 
FROM aircraft, logbook, inspections, installedpart
WHERE aircraft.name = "Cerulean Sky" AND
	logbook.departure = (SELECT MAX(logbook.departure) FROM logbook) AND
	(DATE_ADD(inspection.recertified, INTERVAL 7 DAY) < logbook.departure OR inspection.recertified = NULL)  AND
	aircraft.id = logbook.aircraftid AND aircraft.id = installedpart.aircraftid AND inspections.partid = part.id AND installedpart.id = part.id
ORDER BY inspection.partid ASC

2) If so, can we have their serial numbers, manufacturers, date of last inspection, and
any comments made by the A&P mechanic?

SELECT part.serial, parttype.manufacturer, inspections.recertified, inspections.comments
FROM part, parttype, inspections
WHERE inspections.date = (SELECT MAX(inspections.date) FROM inspections) AND 
	inspection.partid = (repeat answer to part 1 here as a subquery) AND
	parttype.id = part.parttypeid AND part.id = inspections.partid  
ORDER BY part.serial ASC

3) It later turned out that a faulty part made by “Backyard Aircraft Parts and Nuclear
Power, Inc.” was the proximal cause of failure. What percent of aircraft in the fleet have
this part installed?

SELECT (SELECT COUNT(SELECT DISTINCT installedpart.aircraftid FROM installedpart, parttype WHERE parttype.manufacturer = "Backyard Aircraft Parts and Nuclear Power, Inc." AND parttype.id =  installedpart.partid) FROM installedpart)
/ 
(SELECT COUNT(id) FROM aircraft) 
*100.0

Javascript:

1. Create a module containing a function that produces a function that exponentiates a configurable base and prints the result like so:

>>> fn = Module.configure(2)
>>> fn()
1
>>> fn()
2
>>> fn()
4
>>> fn()
8

Notes: 

1. I have written a lot of JavaScript to support Web interfaces and computation within a Web application context and have performed a lot of interactive modular work in both Java and Python. I have not used an interactive JavaScript environment but I understand how to write modular JavaScript. I was taught by strong theoretical programs at Wisconsin and RPI which means the algorithms and design patterns are strong in my head as concepts and then I adapt them based on the features of the programming language I am given or decide to use if responsible for that decision. I think this makes me an awesome thinker and I have written many bridges to inject interpretive languages within compiled languages. I find JavaScript especially intuitive. Perhaps my best relative contribution is how well I work with others in a complex systems environment. I am quick to pick up on ideas suggested by others as well as communicate my own ideas while listening for improvements.

2. I would test this answer on the interactive JavaScript environment you suggest I write for before submitting but you haven't suggested such context. Consider this a strong starting sketch as a result. I have spent 15 minutes on it.

// exponentiate.js
var Module = (function () {

	// Private members
  	var base;
  	var exponent;

	// Public operations
  	return {
      		configure: function (param) { return init(params); },
      		fn: function () { return exponentiate(); }
  	};

	// Private operations
  	function init(param) {
      		base = param;
      		exponent = 0;
  	}

 	function exponentiate() {
 		return Math.pow(base,exponent++);
	}

})(); // Module

2. Pretend you’re writing a three-dimensional geometry program. Show how one might write a “Person” object and derive a “Skateboarder” object from it.

Notes:

1. I have written quite a few three-dimensional geometry programs. I've worked within an awesome team of eight artists and programmers to create a wonderful demonstration game for the Taiwanese government to use to show off new graphics cards in production (that was written in Java 3D and ported to JOGL). I've created many MathLab applications to support graduate work in a computational geometry class that focused on product design. I've played with WebGL quite a bit recently and would love to have a meaty project associated with it. I have played with three-dimensional coding in iOS for six months as part of a client project in Minneapolis (the work didn't get past our proof-of-concept stage as there were funding issues). Below is just a sketch of the inheritance features of JavaScript as that is what I inferred was being asked of me. I started from a simple template I keep around for times like these. I use this template with my students a lot to demonstrate object-oriented design in JavaScript. We've played around with it a lot as a result but never with a skateboarding objective. I spent about 10 minutes on this.

// define the Person Class
function Person() {}

Person.prototype.locomote = function(){
  alert ('I am walking!');
  //...
}
Person.prototype.animate = function(){
  //walk sequence here
}

// define a Skateboarder class
function Skateboarder() {
	// Call the parent constructor
	Person.call(this);
}

// inherit Person
Skateboarder.prototype = new Person();

// correct the constructor pointer because it points to Person
Skateboarder.prototype.constructor = Skateboarder;

// override the locomotive method
Skateboarder.prototype.locomote = function(){
	alert ('I am skating!');
	//...
}

// replace the animate method
Skateboarder.prototype.animate = function(){
 	//skate sequence here
}

// add a sayFU method
Skateboarder.prototype.sayFU = function(){
	alert('FU');
}

var Skateboarder1 = new Skateboarder();
Skateboarder1.locomote();
Skateboarder1.animate();
Skateboarder1.sayFU();

// in order to check inheritance
alert(Skateboarder1 instanceof Person); // true 
alert(Skateboarder1 instanceof Skateboarder); // true

spotify
soundcloud
knockout.js
register.js
node.js