Skip to content

Instantly share code, notes, and snippets.

View darkcris1's full-sized avatar
🎯
Focusing

Cris Fandiño Jr. darkcris1

🎯
Focusing
  • Philippines
View GitHub Profile
@darkcris1
darkcris1 / mergeSort.js
Created January 3, 2021 11:06
Merge Sort Algorithm using javascript
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)
}
@darkcris1
darkcris1 / passwordgenerator.js
Last active February 7, 2021 10:48
Simple password generator
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
@darkcris1
darkcris1 / generateFilePaths.js
Last active January 1, 2021 11:02
Generate a file paths in next.js | This is useful if you are using getStaticPaths
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}/`