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
// const fib = (num) => { | |
// if (num <= 0) return 0; | |
// if (num === 1 || num === 2) return 1; | |
// if (num > 2) { | |
// let prev = 1, next = 1; | |
// for (let i = 3; i <= num; i++) { | |
// let sum = prev + next; | |
// prev = next; | |
// next = sum; | |
// } |
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
const sum = (a, b) => { | |
if (a == 0) return b; | |
if (b == 0) return a; | |
let newA = a ^ b; | |
let newB = (a & b) << 1; | |
return sum(newA, newB); | |
} | |
const a = 10, b = 5; | |
console.log(sum(a, b)); // 15 |
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 length = 10; | |
function fn() { | |
console.log(this.length); | |
} | |
var obj = { | |
length: 5, | |
method: function(fn) { | |
fn(); | |
arguments[0](); |
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 name = 0; | |
var a = { | |
name: 1, | |
f1: function(){ | |
this.name = 2; | |
}, | |
f2: function(){ | |
this.name = 3; | |
return null | |
}, |
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 isType(target, type) { | |
let targetType = Object.prototype.toString.call(target).slice(8, -1).toLowerCase() | |
return targetType === type.toLowerCase() | |
} | |
isType([], 'Array') // true | |
isType(/\d/, 'RegExp') // true | |
isType(new Date(), 'Date') // true | |
isType(function(){}, 'Function') // true | |
isType(Symbol(1), 'Symbol') // 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
function myTrim(str){ | |
let reg = /^\s+|\s+$/g; | |
return str.replace(reg,""); | |
} | |
console.log(myTrim(" abcd ")); // abcd |
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
const arrayToTree = (items) => { | |
let results = []; | |
let map = {}; | |
items.forEach(el => { | |
let item = {...el, children: []}; | |
if (map[item.id]) { | |
item.children = map[item.id]; | |
} else { | |
map[item.id] = item.children; |
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
// in public/config.js | |
window.g = { | |
protocol: 'http', | |
address: '192.168.20.229', | |
port: 18000, | |
timeout: 12 * 1000 | |
} | |
// in http/index.ts |
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
const getMetaData = async () => { | |
// example file path: ./pages/js/*.md | |
const allPostFiles = import.meta.glob('./pages/js/*.md') | |
const iterablePostFiles = Object.entries(allPostFiles) | |
const allPosts = await Promise.all( | |
iterablePostFiles.map(async ([path, resolver]) => { | |
const resolvedPost = await resolver() | |
return { |
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
import { copyToClipboard } from 'utils-snap-fn' | |
const copyIcon = ` | |
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 32 32"><path fill="currentColor" d="M28 10v18H10V10h18m0-2H10a2 2 0 0 0-2 2v18a2 2 0 0 0 2 2h18a2 2 0 0 0 2-2V10a2 2 0 0 0-2-2Z"/><path fill="currentColor" d="M4 18H2V4a2 2 0 0 1 2-2h14v2H4Z"/></svg> | |
` | |
const copiedIcon = ` | |
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 32 32"><path fill="#00a98e" d="m14 21.414l-5-5.001L10.413 15L14 18.586L21.585 11L23 12.415l-9 8.999z"/><path fill="#00a98e" d="M16 2a14 14 0 1 0 14 14A14 14 0 0 0 16 2Zm0 26a12 12 0 1 1 12-12a12 12 0 0 1-12 12Z"/></svg> | |
` |
OlderNewer