Skip to content

Instantly share code, notes, and snippets.

View PantherHawk's full-sized avatar

Alexander Rosenthal PantherHawk

View GitHub Profile
//Generators
// Remember functions?
function doA() {
console.log('did A');
}
function doB() {
console.log('did B')
}
function justAFxn() {
getOpenGraph: function(req, res) {
console.log(req.body.url);
openGraph(req.body.url, function(err, meta) {
if (err) {
console.error(err);
} else {
res.send(meta);
}
});
},
function a() {
setTimeout(function() {
console.log('a');
b();
}, 2000);
};
function b() {
setTimeout(function() {
function a() {
setTimeOut(function() {
console.log('a');
b();
}, 2000);
};
function b() {
setTimeOut(function() {
console.log('b');
function a() {
console.log('a');
}
function b() {
console.log('b');
}
function c() {
console.log('c');
function a() {
setTimeOut(function() {
console.log('a');
b();
}, 2000);
};
fetchFile = (filePath) => {
return new Promise((resolve, reject) => {
readFile(filePath, (err, contents) => {
if (err) { return reject(err); }
});
resolve(contents);
}).then();
};
// A S Y N C H R O N O U S FXN USING A C A L L B A C K
var fetchFile = function(filePath, callback) {
readFile(filePath, (err, contents) => {
if (err) {
return callback(err);
} else {
callback(contents);
}
});
};
function bubbleSort(array) {
var i, j;
for (i = array.length - 1; i >= 0; i--) {
for (j = 0; j <= i; j++) {
if (array[j + 1] < array[j]) {
var temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
let binaryBubbleSort = (array) => {
var lowIndex = array[0];
var highIndex = array[array.length -1];
var timesThrough = 0;
while (lowIndex <= highIndex){
var middleIndex = (highIndex + lowIndex) / 2;
if (array[middleIndex] < value) {
lowIndex = middleIndex + 1;
} else if (array[middleIndex] > value) {