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
var jsList = ["inline.js","polifill.js","vendor.js","main.js"]; | |
var seq = jsList.reduceRight(reducefn,donefn); | |
seq("Start"); | |
function mockExcuteJs(js,fn){ | |
console.log(`Execute ${js}`); | |
fn("Execute "+js+" done."); | |
} |
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
/*isPureObject(item,strict) | |
- item(any) : the target to be checked. | |
- strict(boolean) : if 'true', just original Object can pass the check. | |
*/ | |
function isPureObject(item, strict) { | |
if (item !== null) { | |
if (typeof item === 'object' && !Array.isArray(item)) { | |
if (strict) { | |
if (item.__proto__.__proto__ === null) { | |
return true; |
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
/*=====perfect-scrollbar=====*/ | |
/*--variables---*/ | |
@ps-border-radius: 6px; | |
@ps-rail-default-opacity: 0; | |
@ps-rail-container-hover-opacity: 0.6; | |
@ps-rail-hover-opacity: 0.9; | |
@ps-bar-bg: transparent; | |
@ps-bar-container-hover-bg: #aaa; |
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
//Calculate Excel Date value | |
// Date 1899/12/31 serial number is 1 | |
console.log(getExcelDateValue(new Date(1400,5,8)));//1400/6/8 | |
console.log(getExcelDateValue(new Date(1899,11,31)));//1899/12/31 | |
console.log(getExcelDateValue(new Date()));//now | |
function getExcelDateValue(dateObj){ | |
var year = dateObj.getFullYear(); | |
var month = dateObj.getMonth(); |
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
/** | |
* Reference Satoshi Nakamoto, "Bitcoin: A Peer-to-Peer Electronic Cash System", 2008. | |
* The attacker's potential progress will be a Poisson distribution with expected value. | |
* @param [Number] q Probability the attacker finds the next block,(double). | |
* @param [Number] z The attacker will ever catch up from z blocks behind,(int). | |
**/ | |
function AttackerSuccessProbability(q,z){ | |
//p = probability an honest node finds the next block | |
//q = probability the attacker finds the next block | |
let p = 1.0 - q;//Binomial Random Walk |
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
/*greatest common divisor(最大公因數)*/ | |
function gcd(x,y){ | |
//Euclidean algorithm(輾轉相除法) | |
if(y) | |
while((x%=y) && (y%=x)){} | |
return x+y; | |
} |
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 sieve(x) { | |
let counter = 0; | |
let seq = Array(x - 1).fill(2).map((e, i) => e + i); | |
let primes = []; | |
while (true) { | |
if(seq.length === 0){ | |
console.log(`main loop count : ${counter}`); | |
return primes; | |
} | |
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 leastPrimeFactor(x){ | |
let seq = Array(x+1); | |
seq[1] = 1; | |
for(let i = 2;i<=x;i++){ | |
if(!seq[i]){ | |
seq[i] = i; | |
for(let j=2*i; j<=x;j+=i){ | |
if(!seq[j]) | |
seq[j] = 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
function primeFactorizationBaseOnEratosthenes(x) { | |
if (x === 0) | |
return; | |
let seq = Array(x + 1); //index:0~x | |
let sqrt = Math.sqrt(x); | |
seq[1] = 1; | |
//Base on sieve of Eratosthene.Get store smallest prime factor. |
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 pascal(n) { | |
if (n === 0) | |
return [1]; | |
let prev = n - 1; | |
let times = prev; | |
let leftLength = Math.floor(n / 2) + 1; | |
let lead = Array(prev).fill(1); | |
let temp = [1]; | |
let result_l = [1]; | |
let result_r = [1]; |
OlderNewer