Skip to content

Instantly share code, notes, and snippets.

View jialinhuang00's full-sized avatar
๐Ÿ˜ƒ

jialin.huang jialinhuang00

๐Ÿ˜ƒ
View GitHub Profile
/*-----------------------------------------------------------------------------
the reference is from UdemyCourse: LearningDataStructuresinJavascriptFromScratch
-----------------------------------------------------------------------------*/
function LinkedList() {
this.head = null;
this.tail = null;
}
function Node(value, next, prev) {
/*-----------------------------------------------------------------------------
1.apply what we learn to find to minimun and maximum stock price
2.remember that the sell price is later than the buy price
NOTE: The first function I wrote was too simple to cover the situations
the reference used at the second function is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
function maxStockProfit(priceArr) {
/*-----------------------------------------------------------------------------
split, split til the end we merge them
the reference is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
/*๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ
ๅœจcs50 2016 week3ๆ™‚ๅญธๅˆฐ็š„pseudocode
on input of a elements
/*-----------------------------------------------------------------------------
change, change, just keep changing like bubbles
the reference used at the second function is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
/*๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ
ๅœจcs50 2016 week3ๆ™‚ๅญธๅˆฐ็š„Pseudocode
repeat until now swap
// Using a function in arr.filter(return fun) to check true or false
function Prime(element, index, array) {
var start = 2;
while (start <= Math.sqrt(element)) {
if (element % start++ < 1) {
return false;
}
}
return element > 1;
function fibonacci(n) {
//0,1,1,2,3,5,8,13,21,34,55
var start = [0, 1];
var i, j, k, x;
for (i = 0, j = 1, k = 0; k < n; i = j, j = x, k++) {
x = i + j;
start.push(x);
}
return start[n];
}
/*-----------------------------------------------------------------------------
the reference is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
function binarySearch(numArr, key) {
numArr = numArr.sort((a, b) => a - b);
var midIndex = Math.floor(numArr.length / 2);
var midElement = numArr[midIndex];
/*-----------------------------------------------------------------------------
1.pair off for the required parameter 'sum'.
2.the former by myself is using two loops
3.two ways turned out to be different.
the reference used at the second function is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
function twoSum(numArr, sum) {
// scrutinize every element
/*-----------------------------------------------------------------------------
1.3 function used to calculate: mean, median, mode.
2.writing another function to package them.
3.MODE: if there is no number repeated, return false.
3.MODE: maybe there is not only one mode.
the reference is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
function meanMedianMode(arr) {
/*-----------------------------------------------------------------------------
1.swap the elements
2.temporary variable is useful.
the reference is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
function reverseArrayInPlace(arr) {
// dsakhpr d <-> r s <-> p a <-> h