Skip to content

Instantly share code, notes, and snippets.

View johnfkneafsey's full-sized avatar

John F Kneafsey johnfkneafsey

View GitHub Profile
@johnfkneafsey
johnfkneafsey / Wiseperson
Created November 22, 2016 00:23
Wiseperson
function wisePerson(wiseType, whatToSay) {
return 'A wise ' + wiseType + ' once said: "' + whatToSay + '".';
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
@johnfkneafsey
johnfkneafsey / String Drills
Last active November 22, 2016 00:29
String Drills
function wisePerson(wiseType, whatToSay) {
return 'A wise ' + wiseType + ' once said: "' + whatToSay + '".';
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
@johnfkneafsey
johnfkneafsey / Number Drills
Created November 22, 2016 00:40
Number Drills
function computeArea(width, height) {
return width * height;
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
@johnfkneafsey
johnfkneafsey / Logic Drills
Created November 22, 2016 00:54
Logic Drills
function main() {
try {
doAllTheThings();
}
catch(e) {
console.error(e);
reportError(e);
}
}
@johnfkneafsey
johnfkneafsey / Array Drills
Created November 22, 2016 15:24
Array Drills
function max(numbers) {
var currentMax = numbers[0];
for (var i=0; i <= numbers.length; i++) {
if (numbers[i] > currentMax) {
currentMax = numbers[i];
}
}
return currentMax;
}
@johnfkneafsey
johnfkneafsey / In my own words
Created November 22, 2016 15:47
In my own words
What is scope? Your explanation should include the idea of global vs. local scope.
Scope is a term used to classify parts of your code that have access to a variable. If the scope of the variable is local, any code inside the function can access the variable. Any code outside the function cannot. If the scope of a variabel is global, it means that the variable can be accessed from anywhere.
Why are global variables avoided?
Global variables can be bad for a variety of reasons- they make it difficult to work collaboratively, they can lead to bugs in your code that are difficult to untangle, you can run into concurrency issues, you may confuse global and local variable names, and so on.
Explain JavaScript's strict mode
JS's strict mode disables the use of global variables, forcing the user to define all variables locally.
What are side effects, and what is a pure function?
@johnfkneafsey
johnfkneafsey / Object Drills
Created November 22, 2016 16:01
Object Drills
function createMyObject() {
return {
foo: 'bar',
answerToUniverse: 42,
'olly olly': 'oxen free',
sayHello: function() {
return 'hello';
}
};
}
function mergeDataStreams(stream1, stream2) {
var results = {};
for (var i=0; i < stream1.length; i++) {
results[stream1[i].id] = stream1[i];
}
for (var key in results) {
var otherData = stream2.find(
function(item) { return item.id === key; });
for (var _key in otherData) {
function getDataFromApi(callback) {
var settings = {
url: "https://api.github.com/gists/public",
dataType: 'json',
type: 'GET',
success: callback
};
$.ajax(settings);
}
@johnfkneafsey
johnfkneafsey / get.js
Last active December 19, 2016 02:29
GET endpoint
app.get('/test', function (req, res) {
res.send('Now viewing the test page')
})