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 / isInteresting.js
Created January 3, 2021 11:45
Catching Car Mileage Numbers | Codewars
function isInteresting(number, awesomePhrases = []) {
const str = number.toString(),
isZeros = (num) => /^[1-9](0+)$/.test(num),
isPalindrome = (num) => num.split('').reverse().join('') === num,
isAweP = (num) => awesomePhrases.includes(num),
isSeqInc = (num) =>
RegExp(`${num.length >= 2 ? num : 'a'}`).test('1234567890'),
isSeqDec = (num) =>
RegExp(`${num.length >= 2 ? num : 'a'}`).test('9876543210'),
isClose = (num) => {
@darkcris1
darkcris1 / insertionSort.js
Created January 3, 2021 11:43
Insertion Sort Alagorithm
function insertionSort(arr) {
for (let i = 1; i < arr.length; i++) {
for (let j = i; j > 0; j--) {
if (arr[i] < arr[j - 1]) {
const temp = arr[i]
arr[i] = arr[j - 1]
arr[j - 1] = temp
i--
}
}
@darkcris1
darkcris1 / selectionSort.js
Created January 3, 2021 11:42
Selection Sort Algorithm
function selectionSort(arr) {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length; j++) {
if (arr[i] < arr[j]) {
const temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
}
}
}
@darkcris1
darkcris1 / bubbleSort.js
Created January 3, 2021 11:41
Bubble Sort Algorithm
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
}
}
@darkcris1
darkcris1 / nBonacci.js
Created January 3, 2021 11:38
n-bonacci algorithm | SoloLearn
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)
}
@darkcris1
darkcris1 / strangeRoot.js
Created January 3, 2021 11:28
Strange Root | SoloLearn
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
@darkcris1
darkcris1 / solveExpression.js
Created January 3, 2021 11:23
Find the unknown digit | Codewars
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
}
@darkcris1
darkcris1 / scrabblePoints.js
Created January 3, 2021 11:17
Scrabble points solution | Codewars
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()
@darkcris1
darkcris1 / snailsort algorithm
Created January 3, 2021 11:15
Snailsort Algorithm | Codewars
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()
@darkcris1
darkcris1 / longPrefix.js
Created January 3, 2021 11:12
match a longprefix
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 {