This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* a) modelling our solar system */ | |
function convertDistance(planet) { | |
var kmDistance = planet.distance * 150000000; | |
return kmDistance + ' km.'; | |
} | |
function convertMass(planet) { | |
var kgMass = planet.mass * 5.97; | |
return kgMass + ' 10^24 kg.'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(x, y) { | |
return x / y; | |
} | |
function (array, callback) { | |
array.forEach(callback(element) { | |
}); | |
}; | |
function (callback, array) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function divide(x, y) { | |
return x / y; | |
} | |
function changeArrayElements(array, action) { | |
for (var i = 0; i < array.length; i++) { | |
action(array[i]); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let shortArray = new Array(2) | |
let longArray = new Array(1000) | |
let getNthItem = (n, array) => { | |
return array[n]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let populateArray = (array) => { | |
for (var i of array) { | |
array[i] = i; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetchFile = (filePath) => { | |
return new Promise((resolve, reject) => { | |
readFile(filePath, (err, contents) => { | |
if (err) { return reject(err); } | |
}); | |
resolve(contents); | |
}).then(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function a() { | |
setTimeOut(function() { | |
console.log('a'); | |
b(); | |
}, 2000); | |
}; |
OlderNewer