This file contains hidden or 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 toDecimal(binary) { | |
let decimal = 0; | |
const lastIndex = binary.length; | |
for (let index = 0; index < lastIndex; index++) { | |
const binaryChar = binary[index]; | |
const decimalChar = binaryChar * (2 ** (lastIndex - 1 - index)); | |
decimal += decimalChar; | |
} |
This file contains hidden or 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 toBinary(decimal) { | |
let binary = ""; | |
let rest = decimal; | |
while (rest > 0) { | |
const remainder = String(rest % 2); | |
rest = Math.floor(rest / 2); | |
binary = remainder + binary; | |
} |
This file contains hidden or 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 decode(s) { | |
let newStr = s; | |
const reverse = str => str.split("").reverse().join(""); | |
const getInsideStr = word => { | |
const arr = []; | |
let str = ""; | |
for (let index = 0; index < word.length; index++) { |
This file contains hidden or 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(array) { | |
// Only change code below this line | |
let newArray = []; | |
let smallest = array[0]; | |
let biggest = array[0]; | |
newArray.push(smallest); | |
for (let i = 1; i < array.length; i++) { | |
const currItem = array[i]; |
This file contains hidden or 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 sym(...args) { | |
let diff = []; | |
const checkArrays = (firstArray, secondArray) => { | |
const currentDiff = []; | |
for (let i = 0; i < firstArray.length; i++) { | |
const currValFstArr = firstArray[i]; | |
if (!secondArray.includes(currValFstArr)) { | |
currentDiff.push(currValFstArr); |
This file contains hidden or 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 telephoneCheck(str) { | |
const regex = /^(1)?\s?((\(\d{3}\))|(\d{3}))\s?-?(\d{3})\s?-?(\d{4})$/g | |
return regex.test(str); | |
} |
This file contains hidden or 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 currency = [ | |
{ | |
name: "PENNY", | |
value: 0.01, | |
next: 0.05 | |
}, | |
{ | |
name: "NICKEL", | |
value: 0.05, | |
next: 0.1 |
This file contains hidden or 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 rot13(str) { | |
const placesToRight = 13; | |
const letterA = 65; | |
const letterZ = 90; | |
const newStr = []; | |
for (let i=0; i<str.length; i++) { | |
const charCode = str.charCodeAt(i); | |
let newCharCode = charCode + placesToRight; |
This file contains hidden or 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 isPrime = number => { | |
let isPrime = true; | |
for (let i = 2; i < number; i++) { | |
if (number % i == 0) { | |
isPrime = false; | |
break; | |
} | |
} | |
return isPrime; |
This file contains hidden or 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 fibonacci(num) { | |
let total = 1; | |
let oldValue = 1; | |
let arr = []; | |
for (let i = 0; i < num; i++) { | |
arr.push(total); | |
if (i > 0) { | |
oldValue = arr[i-1]; | |
} |
NewerOlder