This file contains hidden or 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 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]; | |
} |
This file contains hidden or 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
// 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; |
This file contains hidden or 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
/*----------------------------------------------------------------------------- | |
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 |
This file contains hidden or 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
/*----------------------------------------------------------------------------- | |
split, split til the end we merge them | |
the reference is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch | |
-----------------------------------------------------------------------------*/ | |
/******************************************* | |
在cs50 2016 week3時學到的pseudocode | |
on input of a elements |
This file contains hidden or 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
/*----------------------------------------------------------------------------- | |
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) { |
This file contains hidden or 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
/*----------------------------------------------------------------------------- | |
the reference is from UdemyCourse: LearningDataStructuresinJavascriptFromScratch | |
-----------------------------------------------------------------------------*/ | |
function LinkedList() { | |
this.head = null; | |
this.tail = null; | |
} | |
function Node(value, next, prev) { |
This file contains hidden or 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
/*----------------------------------------------------------------------------- | |
the reference is from UdemyCourse: LearningDataStructuresinJavascriptFromScratch | |
-----------------------------------------------------------------------------*/ | |
function BST(value) { | |
this.value = value; | |
this.left = null; | |
this.right = null; | |
} | |
This file contains hidden or 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
/*----------------------------------------------------------------------------- | |
the reference is from UdemyCourse: LearningDataStructuresinJavascriptFromScratch | |
-----------------------------------------------------------------------------*/ | |
function HashTable(size) { | |
this.buckets = Array(size); | |
this.numBuckets = this.buckets.length; | |
} | |
function HashNode(key, value, next) { |
This file contains hidden or 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
※ 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. 的確是數字 | |
This file contains hidden or 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
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); | |
} |