利用js-xlsx
来导出excel,纯前端实现实现
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
class PriorityQueue { | |
constructor(data = [], compare = defaultCompare) { | |
this.data = data | |
this.length = this.data.length | |
this.compare = compare | |
if (this.length > 0) { | |
for (let i = (this.length >> 1) - 1; i >= 0; i--) this._down(i) | |
} | |
} |
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
// Sequence generator function (commonly referred to as "range", e.g. Clojure, PHP etc) | |
const range = (start, stop, step) => Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step)); | |
// create 2d array | |
const create2DArray = (m, n, initVal) => Array.from(new Array(m), () => new Array(n).fill(initVal)) | |
// create 3d array | |
const create3DArray = (m, n, d, initVal) => Array.from(new Array(m), () => Array.from(new Array(n), () => new Array(d).fill(initVal))) |
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 base58(encodeMap) { | |
function base58encode(int64: string): string { | |
let num = BigInt(int64) | |
const base = 58n | |
let res = '' | |
while (num >= base) { | |
res += encodeMap[num % base] | |
num = num / base | |
} |
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 generatePassword(length) { | |
let charsets = ['ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz', '0123456789', '!#$%&*'] | |
let allCharsets = charsets.join('') | |
let retVal = '' | |
for (let i = 0, len = charsets.length; i < len; i++) { | |
let n = charsets[i].length |
1.递归
function recur(level, params...) {
// 终止条件
if (level < maxLevel) {
process_result
return
}
// 处理当前层
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 genArray(rows, cols, something) { | |
// BAD! Rows are copied by reference | |
// return new Array(rows).fill(new Array(cols).fill(something)) | |
// good way | |
Array.from(Array(rows), () => new Array(cols).fill(something)) | |
// more inefficient 12% | |
// return new Array(rows).fill(null).map(() => Array(cols).fill(something)) | |
} |
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 range(start, end, step) { | |
if (arguments.length === 0) { | |
throw new Error('range fuction expect at least 1 argument') | |
} | |
if (arguments.length === 1) { | |
end = start | |
start = 0 | |
step = 1 |
NewerOlder