Building a REST API

Navigate to the repo location in terminal:

cd AutomationDatatools/distillery/

Start the server

DEBUG=distillery ./bin/www

Go to your web browser and navigate to the localhost

http://localhost:3000/api/imsreports

The structure looks like this for public, routes and views:

|– public
|   `– stylesheets
|       `– style.css
|– routes
|   |– api
|   |   |– imsreports.js
|   |   `– index.js
|   `– index.js
`– views
|– api
|   `– index.ejs
|– error.ejs
|– index.ejs
`– main.ejs

Advertisements

Code School Part 3 Exercise 1.13

This one stumped me for a bit. In scrum a fellow teammate said he’d offer some suggestions if I sent him my code.

This was my code prior to suggestions from teammate:

var applyAndEmpty = function(input, queue){
var amount = queue.length;
for (var i=0;i<amount.length;i++){
input = queue(input);
var removeFirst = queue.shift();
}
};

return applyAndEmpty(start, puzzlers);

This is my final code that worked in the exercise:

var puzzlers = [
function(a) { return 8 * a – 10; },
function(a) { return (a – 3) * (a – 3) * (a – 3); },
function(a) { return a * a + 4; },
function(a) { return a % 5; }
];
var start = 2;
var applyAndEmpty = function(input, queue){
var amount = queue.length;
for (var i=0;i<amount;i++){
input = queue.shift()(input);
}
return input;
};
alert(applyAndEmpty(start, puzzlers));

My teammate pointed out that I was calling .length twice. With the below statement, I was so close! They were not the right syntax and I was writing more complex statements than they had to be.

input = queue(input);
var removeFirst = queue.shift();

My code also had the applyAndEmpty as a return statement and it should have been an alert statement.

Puzzle Exercise Instructions

Now the people at Poplar Puzzles would like you to treat an array of functions like a Queue, passing the result of each function into the next until the Queue is empty. They’ve sent you the puzzlers Queue of functions, and the following instructions:

In a variable called applyAndEmpty, build and store a function that takes in an input number and a Queue of functions as parameters. Using a for loop, apply the Queue’s functions in order to the input number, where the results of each function become the next function’s input. Additionally, the Queue should be empty after the function is called. – PuZzLe MaSTeRs

Lastly, call the applyAndEmpty function using the provided start variable and the puzzlers Queue as arguments, and alert the result.

Error Message with incorrect code

Incorrect Submission: Make sure that you declare the applyAndEmpty variable properly.

 

More of my CodeSchool JavaScript Road Trip journey can be found on GitHub.

Code School JavaScript Road Trip Part 3

For a new project, I’m taking the Code School JavaScript trainings and I’m finding the stories and the problems to solve quite enjoyable as compared to Code Academy. It was smooth sailing until Road Trip Part 3, where my velocity slowed due to the complexity of the problem statements. I’ve realized that there are many ways to solve the problem and the way I’d solve them is not the point of the lesson, which is good because it’s teaching me new ways of looking at a problem.

My code, and thoughts on solving problems with CodeSchool Javascript Road Trip is logged in GitHub.