vlad
New Coder
Hi everyone,
I’m working on a JavaScript task and can't find a solution that satisfies all the given constraints.
Test cases:
If anyone has advice, a direction, or a working example that respects the constraints, I’d really appreciate the help!
I’m working on a JavaScript task and can't find a solution that satisfies all the given constraints.
Task:
Write a function countEmoji(message, emoji) that counts the occurrences of a specific emoji for each mentioned user in a message.Constraints:
- Use only one loop (and it must be for loop).
- Use one object to store the results.
- Use charCodeAt to identify specific characters and fromCharCode for character conversion to lowercase.
- No built-in methods for strings or arrays (e.g., split, match, forEach, etc.).
Additional Rule:
If there’s no valid emoji patern with needed emoji between two user mentions, group the users and count the next valid emojis for all grouped users.Test cases:
JavaScript:
const text = '<@Kate />:apple: <@Max/>:like:<@alisa /> :like: received:apple::apple:'
countEmoji(text, 'apple');
//expected result
//{
//kate: 1,
//max: 2,
//alisa: 2
//}
//const text = '<@Kate />:apple: <@Max/>:apple: :APPLE: :AppLe:<@alisa /> :like: received:apple::apple:'
//{
//kate: 1,
//max: 3,
//alisa: 2
//}
//const text = '<@Kate />:apple: <@Max/>:apple APPLE: AppLe:<@alisa /> :like: received:apple::apple:'
//{
//kate: 1,
//max: 2,
//alisa: 2
//}
//const text = '<@Kate />:apple: <@Max/>:like:<@alisa /> :like: received:apple::apple: <@kate / > alsdaksdjhsa <@KATE / > :apple: :apple:'
//{
//kate: 3,
//max: 2,
//alisa: 2
//}
//const text = '<@Kate />:apple: <@Max/><@olia/><@misha/><@dasha/><@alisa /> :like: received:apple::apple: <@dima/><@vasia/><@gena/><@ihor/><@tolik />'
//{
//kate: 1,
//max: 2,
//alisa: 2,
//olia:2,
//misha:2,
//dasha:2,
//dima:0,
//vasia:0,
//gena:0,
//ihor:0,
//tolik:0
//}
//const text = ':apple: :apple: <@Kate />:apple: <@Max/><@alisa /> :like: received:apple::apple: '
//{
//kate: 1,
//max: 2,
//alisa: 2
//}
Challenges Faced:
I’ve tried various approaches, but either I exceed the constraints (e.g., using multiple loops or arrays with methods like forEach) or fail to handle all edge cases.If anyone has advice, a direction, or a working example that respects the constraints, I’d really appreciate the help!
Last edited: