Skip to content

Patterns

Arghun-dev edited this page Jul 23, 2021 · 12 revisions

Frequency Counters

this pattern uses objects or sets to collect values/frequencies of values.

this can often avoid the need for nested loops or O(N^2) operations with arrays and strings.

Example

write a function which accepts two arrays. the function should return true if every value in the array has it's corresponding value squared in the second array. the frequency of values must be the same.

same([1,2,3], [4,1,9]) // true
same([1,2,3], [4,1,6]) // false

Clone this wiki locally