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
| const tree = { | |
| name: "A", | |
| children: [ | |
| { name: "A-1", children: [{ name: "A-1-A" }, { name: "A-1-B" }] }, | |
| { | |
| name: "B-1", | |
| children: [ | |
| { name: "B-1-A", children: [{ name: "B-11-A" }, { name: "B-11-B" }] }, | |
| { name: "B-1-B" } | |
| ] |
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
| const permutation = text => { | |
| return permute("", text); | |
| }; | |
| const permute = (prefix, sufix, arr = []) => { | |
| if (sufix.length == 0) arr.push(prefix); | |
| else { | |
| for (let i = 0; i < sufix.length; i++) { | |
| permute( | |
| prefix + sufix.charAt(i), | |
| sufix.substr(0, i) + sufix.substr(i + 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
| const source = [ | |
| { Id: "1", Name: "abc", Parent: "", attr: "abc" }, | |
| { Id: "2", Name: "abc", Parent: "1", attr: "abc" }, | |
| { Id: "3", Name: "abc", Parent: "2", attr: "abc" }, | |
| { Id: "4", Name: "abc", Parent: "2", attr: "abc" }, | |
| ]; | |
| function tree(data, id, pId) { | |
| const [result] = data.reduce( | |
| ([r, map], item) => { | |
| const d = { ...item, children: [] }; |
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
| const sort_table = ( | |
| sortColNum, | |
| id = "#table_data", | |
| isLastRowTable = true, | |
| formatter = td => td.textContent, | |
| reIndex = 1 | |
| ) => { | |
| let elm = document.querySelector(id); | |
| if (!elm) { | |
| document.querySelector("table").tBodies[0].setAttribute("id", "table_data"); |
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
| const _ = {}; | |
| // fn: (any[], function, () => boolean) -> any[] | |
| _.tillWhen = (data, fn, predicate) => { | |
| if (!data || !Array.isArray(data)) return data; | |
| let index = 0; | |
| let arr = []; | |
| do { | |
| arr.push(fn(data[index])); | |
| } while (index < data.length && !predicate(data[index++])); | |
| return arr; |
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 conditionalBreak() { | |
| let x = 0; | |
| let z = 0; | |
| while (true) { | |
| console.log("Outer loops: " + x); | |
| x += 1; | |
| z = 1; | |
| let breakOuterLoop = false; | |
| while (true) { | |
| console.log("Inner loops: " + z); |
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 labeledLoop() { | |
| let x = 0; | |
| let z = 0; | |
| outer: while (true) { | |
| console.log("Outer loops: " + x); | |
| x += 1; | |
| z = 1; | |
| while (true) { | |
| console.log("Inner loops: " + z); | |
| z += 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
| // For | |
| function howMany(selectObject) { | |
| let numberSelected = 0; | |
| for (let i = 0; i < selectObject.options.length; i++) { | |
| if (selectObject.options[i].selected) { | |
| numberSelected++; | |
| } | |
| } | |
| return numberSelected; | |
| } |
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
| package main | |
| import ( | |
| "io" | |
| "net/http" | |
| "os" | |
| ) | |
| func check(e error) { | |
| if e != nil { |
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
| const http = require("http"); | |
| const fs = require("fs"); | |
| function main() { | |
| const server = http.createServer((req, res) => { | |
| // console.time("START:NODE"); | |
| fs.createReadStream("./test1.txt") | |
| .pipe(res) | |
| // .on("finish", () => { | |
| // console.timeEnd("START:NODE"); |