Skip to content

Instantly share code, notes, and snippets.

View jialinhuang00's full-sized avatar
😃

jialin.huang jialinhuang00

😃
View GitHub Profile
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];
}
// 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;
/*-----------------------------------------------------------------------------
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
/*-----------------------------------------------------------------------------
split, split til the end we merge them
the reference is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
/*******************************************
在cs50 2016 week3時學到的pseudocode
on input of a elements
/*-----------------------------------------------------------------------------
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) {
/*-----------------------------------------------------------------------------
the reference is from UdemyCourse: LearningDataStructuresinJavascriptFromScratch
-----------------------------------------------------------------------------*/
function LinkedList() {
this.head = null;
this.tail = null;
}
function Node(value, next, prev) {
/*-----------------------------------------------------------------------------
the reference is from UdemyCourse: LearningDataStructuresinJavascriptFromScratch
-----------------------------------------------------------------------------*/
function BST(value) {
this.value = value;
this.left = null;
this.right = null;
}
/*-----------------------------------------------------------------------------
the reference is from UdemyCourse: LearningDataStructuresinJavascriptFromScratch
-----------------------------------------------------------------------------*/
function HashTable(size) {
this.buckets = Array(size);
this.numBuckets = this.buckets.length;
}
function HashNode(key, value, next) {
@jialinhuang00
jialinhuang00 / isNaN.txt
Created October 31, 2017 14:38
dig deeper for isNaN()
※ NaN === NaN --> false
※ isNaN(NaN) --> true
※ typeof NaN --> 'number'
※ isNaN(x)、isNaN(x - 0)、isNaN(Number(x))、Number.isNaN(x - 0)、Number.isNaN(Number(x))都是一樣的東西
一、false狀況下:
1. 的確是數字
var arr = ['a', 'b', 'c', 'd', 'e'];
var eArr = arr.entries();
console.log(eArr.next()); // { value: [ 0, 'a' ], done: false }
console.log(eArr.next().value); // [1, 'b']
// 剩下c,d,e還沒跑出來,所以...
for (let e of eArr) {
console.log(e);
}