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 countUniqueValues(arr){ | |
if (arr.length === 0) return 0; | |
let unique = 0; | |
let lookAhead = 1; | |
while (lookAhead < arr.length) { | |
if (arr[unique] !== arr[lookAhead]) { | |
unique++; | |
arr[unique] = arr[lookAhead]; |
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 averagePair(arr, average) { | |
if (arr.length < 2) return false; | |
let left = 0; | |
let right = arr.length - 1; | |
const findAverage = (num1, num2) => { | |
return (num1 + num2) / 2; | |
} |
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 areThereDuplicates(...arr) { | |
if (arr.length === 0) return false; | |
arr = arr.sort(); | |
let unique = 0; | |
for (let index = 1; index < arr.length; index++) { | |
if (arr[unique] === arr[index]) { | |
return true; |
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 validAnagram (firstStr, secondStr) { | |
if (firstStr.length !== secondStr.length) return false; | |
let freqCount = {}; | |
for (let x of firstStr) { | |
freqCount[x] = (freqCount[x] || 0) + 1 | |
} | |
for (let y of secondStr) { |
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 sameFrequency(first, second){ | |
const firstStr = first.toString(); | |
const secondStr = second.toString(); | |
if (firstStr.length !== secondStr.length) return false; | |
let frequencyCounter = {}; | |
for (let x of firstStr) { | |
frequencyCounter[x] = (frequencyCounter[x] || 0) + 1; |
NewerOlder