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; |
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 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 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 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 isSubsequence(first, second) { | |
if (first.length > second.length) return false; | |
if (!first) return true; | |
let i = 0; | |
let j = 0; | |
while (j < second.length) { | |
if (first[i] === second[j]) 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 maxSubarraySum(arr, window){ | |
if (arr.length < window) return null; | |
let tempSum = 0; | |
for (let x = 0; x < window; x++) { | |
tempSum += arr[x] | |
} | |
let maxSum = tempSum; |
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 minSubArrayLen(nums, sum) { | |
let total = 0; | |
let start = 0; | |
let end = 0; | |
let minLen = Infinity; | |
while (start < nums.length) { | |
if(total < sum && end < nums.length){ | |
total += nums[end]; | |
end++; |
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 findLongestSubstring(str) { | |
if (str.length === 0) return 0; | |
let maxLen = -Infinity; | |
let start = 0; | |
let end = 0; | |
let strObj = {}; | |
while (start < str.length) { | |
const endLetter = str[end]; |
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 chunkArrayInGroups(arr, size) { | |
// Base condition | |
if (arr.length <= size) return [arr]; | |
// Recursive case | |
return [arr.slice(0, size), ...chunkArrayInGroups(arr.slice(size), size)] | |
} | |
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 2); // [[0, 1], [2, 3], [4, 5], [6]] |
OlderNewer