|
|
@@ -27,4 +27,108 @@ function isDoubloon(input) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
console.log(isDoubloon('Jaja')); |
|
|
|
function isDoubloon2(word) { |
|
|
|
word = word.toLowerCase(); |
|
|
|
for (let i = 0; i < word.length; i++) { |
|
|
|
let testCharOuter = word[i]; |
|
|
|
console.log(testCharOuter); |
|
|
|
let count = 0; |
|
|
|
for (let j = 0; j < word.length; j++) { |
|
|
|
let testCharInner = word[j]; |
|
|
|
console.log('--' + testCharInner); |
|
|
|
if (word[i] === word[j]) { |
|
|
|
count++; |
|
|
|
} |
|
|
|
} |
|
|
|
if (count !== 2) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
function canSpell(word, tiles) { |
|
|
|
tiles = tiles.split(''); |
|
|
|
for (let i = 0; i < word.length; i++) { |
|
|
|
let testChar = word[i]; |
|
|
|
let index = tiles.indexOf(testChar); |
|
|
|
if (index < 0) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
tiles[index] = null; |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
function isPalindrome(input) { |
|
|
|
const regex = /[\W_]/g; |
|
|
|
input = input.toLowerCase().replace(regex, ''); |
|
|
|
if (input === input.split('').reverse().join('')) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
function isPalindrome2(input) { |
|
|
|
const regex = /[\W_]/g; |
|
|
|
input = input.toLowercase().replace(regex, ''); |
|
|
|
} |
|
|
|
|
|
|
|
function customLowerCase(input) { |
|
|
|
let output = ''; |
|
|
|
for (let i = 0; i < input.length; i++) { |
|
|
|
let charCode = input.charCodeAt(i); |
|
|
|
if (charCode >= 65 && charCode <= 90) { |
|
|
|
output += String.fromCharCode(charCode + 32); |
|
|
|
} else { |
|
|
|
output += String.fromCharCode(charCode); |
|
|
|
} |
|
|
|
} |
|
|
|
return output; |
|
|
|
} |
|
|
|
|
|
|
|
function isPrime(num) { |
|
|
|
for (let i = 2; i < num; i++) |
|
|
|
if (num % i === 0) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
return num > 1; |
|
|
|
} |
|
|
|
|
|
|
|
function getPrimes(n) { |
|
|
|
let sieve = []; |
|
|
|
for (let i = 1; i <= n; i++) { |
|
|
|
sieve.push(true); |
|
|
|
} |
|
|
|
for (let i = 2; i <= n; i++) { |
|
|
|
if (sieve[i]) { |
|
|
|
for (let j = i * 2; j <= n; j += i) { |
|
|
|
sieve[j] = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
let primes = []; |
|
|
|
for (let i = 2; i <= n; i++) { |
|
|
|
if (sieve[i]) { |
|
|
|
primes.push(i); |
|
|
|
} |
|
|
|
} |
|
|
|
return primes; |
|
|
|
} |
|
|
|
|
|
|
|
function bubbleSort(arr) { |
|
|
|
let sorted = false; |
|
|
|
while (!sorted) { |
|
|
|
sorted = true; |
|
|
|
for (i = 0; i < arr.length; i++) { |
|
|
|
if (arr[i] > arr[i + 1]) { |
|
|
|
[arr[i], arr[i + 1]] = [arr[i + 1], arr[i]]; |
|
|
|
sorted = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
test = [5, 7, 99, 1, 3, 796, -1, 0]; |
|
|
|
bubbleSort(test) |
|
|
|
console.log(test); |