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 fs from 'fs' | |
const ignoreRegex = /_(.*?).md/ | |
const isMd = (value) => /\.md$/.test(value) | |
function generateMdPaths(data, currentPath = '', ext = '') { | |
return data.reduce((acc, value) => { | |
if (ignoreRegex.test(value)) return acc | |
if (!isMd(value)) { | |
const path = `${currentPath}/${value}/` |
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 generatePassword(length = 50) { | |
if (length < 5) throw new Error('Length must be minimum of 5') | |
const chars = 'abcdefghijklmopqrstnuvwxyz-[]{}()*-+,./\\1234567890' | |
let result = '' | |
for (let i = 0; i < length; i++) { | |
const randomChars = chars[Math.floor(Math.random() * chars.length)] | |
result += randomChars | |
} | |
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 sort(arrL, arrR) { | |
const newArray = [] | |
while (arrL.length && arrR.length) { | |
arrR[0] < arrL[0] | |
? newArray.push(arrR.shift()) | |
: newArray.push(arrL.shift()) | |
} | |
return newArray.concat(arrL, arrR) | |
} |
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 longPrefix(arr) { | |
let result = '' | |
if (arr.length === 0) return result | |
for (let i = 0; i < arr[0].length || 0; i++) { | |
for (let j = 1; j < arr.length; j++) { | |
if (arr[0][i] === arr[j][i]) { | |
if (j + 1 === arr.length) { | |
result += arr[0][i] | |
} | |
} 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 snailSort = (arr) => { | |
let result = [] | |
while (arr.length) { | |
if (arr.length === 1) { | |
return [...result, ...arr[0]] | |
} | |
for (let i = 0; i < arr[0].length; i++) { | |
result.push(arr[0][i]) | |
} | |
arr.shift() |
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 scrabblePoints(str) { | |
const strs = str.split(' ') | |
let letterPoints = 0 | |
const totalPoints = strs.reduce( | |
(acc, value) => { | |
if (value.length > 10 || !value) return acc | |
console.log(value) | |
value | |
.trim() | |
.toLowerCase() |
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 solveExpression(exp) { | |
for (let i = 0; i <= 9; i++) { | |
const ex = exp.replace(/\?/g, i).split('=') | |
if (/--/.test(ex[0])) { | |
ex[0] = ex[0].replace(/(-([0-9]+))/g, '($1)') | |
} | |
if (/\b00|00\b/g.test(ex.join('='))) continue | |
if (exp.includes(i)) continue | |
if (eval(ex[0]) == ex[1]) return i | |
} |
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 strangeRoot(n) { | |
const sqrt = Math.sqrt(n) | |
.toFixed(3) | |
.replace(/\.(0{3})$/, '') | |
return new RegExp(n * n).test(sqrt) | |
} | |
console.log(strangeRoot(2)) // true | |
// Strange Root Visualize |
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 nFibonacci = (n, max) => { | |
const result = Array(n) | |
.fill(0) | |
.fill(1, n - 1 || 1) | |
for (let i = result.length; i < max; i++) { | |
const nSums = result | |
.slice(result.length - n) | |
.reduce((acc, val) => BigInt(acc) + BigInt(val), 0) | |
result.push(nSums) | |
} |
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 bubbleSort(arr) { | |
for (let i = 0; i < arr.length; i++) { | |
for (let j = 1; j < arr.length; j++) { | |
if (arr[j] < arr[j - 1]) { | |
const temp = arr[j - 1] | |
arr[j - 1] = arr[j] | |
arr[j] = temp | |
} | |
} |
OlderNewer