Last active
February 28, 2023 17:14
-
-
Save 0851/f05dac9c01b84afbfab30b5935e31aed to your computer and use it in GitHub Desktop.
代码片段
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
find.js | |
filter.js | |
weixinshare.js |
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 filter(any, cb) { | |
if (any === null) { | |
return | |
} | |
const result = []; | |
function pushStack(curr, stack) { | |
let newStack; | |
if (curr.length) { | |
newStack = curr | |
} else { | |
const children = curr.children; | |
if (!children || !children.length) { | |
return; | |
} | |
newStack = children | |
} | |
Array.prototype.push.apply(stack, newStack); | |
} | |
function __(any) { | |
let stack = []; | |
if (cb(any) === true) { | |
result.push(any) | |
} | |
pushStack(any, stack); | |
while (stack.length) { | |
const current = stack.shift(); | |
if (cb(current) === true) { | |
result.push(current) | |
} | |
pushStack(current, stack); | |
} | |
} | |
__(any); | |
return result; | |
} |
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 find(any, cb) { | |
if (any === null) { | |
return | |
} | |
function pushStack(curr, stack) { | |
let newStack; | |
if (curr.length) { | |
newStack = curr | |
} else { | |
const children = curr.children; | |
if (!children || !children.length) { | |
return; | |
} | |
newStack = children | |
} | |
Array.prototype.push.apply(stack, newStack); | |
} | |
function __(any) { | |
let stack = []; | |
if (cb(any) === true) { | |
return any | |
} | |
pushStack(any, stack); | |
while (stack.length) { | |
const current = stack.shift(); | |
if (cb(current) === true) { | |
return current | |
} | |
pushStack(current, stack); | |
} | |
} | |
return __(any); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment