fave77 / Mathball

A JavaScript library for Competitive Programming
https://fave77.github.io/Mathball-Docs/
MIT License
99 stars 49 forks source link

Frequency #36

Closed fave77 closed 5 years ago

fave77 commented 5 years ago

Do the checklist before filing the issue:

NOTE: Provide a clear and concise description of the feature that needs to be added! Or if its a bug, then provide the necessary steps to reproduce it along with screenshots.

[Function: M.frequency()] needs to be added! For more info:

Find the frequency of a number or string in an array & substring in a string!

Usage:

// number or string in an array
console.log(M.frequency([1, 2, 3, 1, 2, 4, 5, 1], 1));                             /* 3 */
console.log(M.frequency(['a', 'y', 'a', 'b', 'c', 'z', 'i'], 'a'));                /* 2 */
console.log(M.frequency(['hello', 'world', 'lorem', 'ipsum', 'hello'], 'world'));  /* 1 */
console.log(M.frequency(['hello', 5, 'lorem', 7, 'ipsum', 'hello'], 'world'));     /* 0 */

//substring in a string
console.log(M.frequency('banana', 'ana'));      /* 2 */  
console.log(M.frequency('banana', 'an'));       /* 2 */
console.log(M.frequency('banana', 'a'));        /* 3 */

NOTE: For any other arguments include appropriate TypeErrors!

Category: Mathematical Utilities

abdus commented 5 years ago

Assign me, please.

fave77 commented 5 years ago

@thisisabdus you're assigned!

abdus commented 5 years ago

Thank you!