Skip to content

Instantly share code, notes, and snippets.

View marsgpl's full-sized avatar
🔴
Recording

Iurii Belobeev marsgpl

🔴
Recording
View GitHub Profile
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]])
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 {
const getPrimes = function(n) {
const result = []
for ( let i=2;i<=n;++i ) {
if ( getPrimes.isPrime(i) ) {
result.push(i)
}
}
return result
const Stack = function(data = []) {
this.data = data
}
Stack.prototype.push = function(value) {
this.data.push(value)
}
Stack.prototype.pop = function() {
return this.data.pop()
const example = "(2+2.0) *2"
const calculator = expr => {
while ( expr.match(/\(/) ) {
expr = expr.replace(/\(([^\)]+)\)/g, (_,subExpr) => calculator(subExpr))
}
while ( expr.match(/[\*\/]/) ) {
expr = expr.replace(/([0-9\.]+)\s*([\*\/])\s*([0-9\.]+)/g, calculator.process)
}
const addOne = arr => arr.reduceRight((acc, v, i) => {
if ( i==arr.length-1 || arr[i+1] == 9 ) {
if ( v == 9 ) {
acc.push(0)
if ( i==0 ) {
acc.push(1)
}
} else {
acc.push(v+1)