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 'package:url_launcher/url_launcher.dart'; | |
Future<bool> openUrl(String url) async { | |
if (url == null || url.trim().length == 0) { | |
return false; | |
} | |
url = Uri.encodeFull(url.trim()); | |
if (!url.contains('://')) { |
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 fetch = require("node-fetch") | |
const fetchAll = async function(urls, max=3) { | |
const results = Array(urls.length) | |
const workers = Array(max) | |
const index = {value:0} | |
for (let i=0; i<max; ++i) { | |
workers.push(fetchAll.worker(urls, results, index)) | |
} |
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 rotateWords = function(arr) { | |
rotateWords.reverse(arr, 0, arr.length-1) | |
let firstSpaceIndex = arr.indexOf(" ") | |
let secondSpaceIndex = arr.indexOf(" ", firstSpaceIndex + 1) | |
rotateWords.reverse(arr, 0, firstSpaceIndex - 1) | |
rotateWords.reverse(arr, firstSpaceIndex + 1, secondSpaceIndex - 1) | |
rotateWords.reverse(arr, secondSpaceIndex + 1, arr.length - 1) |
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
// ABAZDC, BACBAD => ABAD | |
// AGGTAB, GXTXAYB => GTAB | |
// aaaa, aa => aa | |
const getLongestSubseq = function(s1, s2) { | |
let longest = null | |
for ( let s1from=0; s1from<s1.length; ++s1from ) { | |
let current = [] | |
let s1i = s1from, s2i = 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
const genBrackets = function(n) { | |
const result = [] | |
if ( n > 0 ) { | |
genBrackets.add(n, 0, "", result) | |
} | |
return result.join(" ") | |
} |
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 moneyTypes = [5000, 1000, 500, 100, 50, 30] | |
var lims = { | |
5000: 4, | |
1000: 5, | |
500: 2, | |
100: 5, | |
50: 100, | |
30: 23 | |
} |
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 getAnagrams = function(...args) { | |
const anagrams = [] | |
const candidates = {} | |
for ( let word of args ) { | |
let wordNorm = getAnagrams.normalize(word) | |
if ( candidates[wordNorm] ) { | |
anagrams.push([word, candidates[wordNorm]]) |
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 check = function(seq) { | |
let opened = [] | |
for ( let char of seq ) { | |
if ( check.openers[char] ) { | |
opened.push(char) | |
} else { // closers | |
if ( opened.length==0 || opened[opened.length-1] !== check.closers[char] ) { | |
return false | |
} else { |
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 getPrimes = function(n) { | |
const result = [] | |
for ( let i=2;i<=n;++i ) { | |
if ( getPrimes.isPrime(i) ) { | |
result.push(i) | |
} | |
} | |
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
const Stack = function(data = []) { | |
this.data = data | |
} | |
Stack.prototype.push = function(value) { | |
this.data.push(value) | |
} | |
Stack.prototype.pop = function() { | |
return this.data.pop() |