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 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) => { |
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 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-- | |
} | |
} |
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 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 | |
} | |
} | |
} |
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 | |
} | |
} |
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 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
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 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
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 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 { |