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
| 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
| 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 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 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 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 snippets = [ | |
| { | |
| scope: "javascript,typescript", | |
| prefix: "st_key_map", | |
| body: `const mapKeys = (obj, fn) => { | |
| let mapper = fn; | |
| if (typeof fn === "string") mapper = x => x[fn]; | |
| return Object.keys(obj).reduce((acc, k) => { | |
| acc[mapper(obj[k], k, obj)] = obj[k]; | |
| return acc; |
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 TicTac { | |
| constructor() { | |
| this.mat = [ | |
| [-1, -1, -1], | |
| [-1, -1, -1], | |
| [-1, -1, -1], | |
| ]; | |
| } | |
| move(i, j, m) { | |
| m ? this.moveX([i, j]) : moveO([i, j]); |
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
| <!doctype html> | |
| <html class="no-js" lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Document</title> | |
| <link rel="stylesheet" href="app.css"> | |
| <style> | |
| td { | |
| border: 1px solid; |
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
| /* | |
| // How to use | |
| curl -s https://gist.githubusercontent.com/deepakshrma/c77d297d5ff3e07ce172da2893bb49d0/raw/835f004cf234cf3a79fab1bd1b37df7db861773b/nodejs_init.js -O nodejs_init.js || node nodejs_init.js | |
| */ | |
| const path = require("path"); | |
| const fs = require("fs"); | |
| const cwd = process.cwd(); | |
| const fromRoot = (...args) => path.join(cwd, ...args); |