JavaScript Problem: Counting Duplicate Elements in an Array

preview_player
Показать описание
In this tutorial we are going to tackle a JavaScript problem of counting duplicate elements in an array. We are going to look at a couple of different ways solve this using forEach, reduce and the comma operator.

Would you like to help keep this channel going?

Tutorials referred to in this video:

For more resources on JavaScript:

#javascript #AllThingsJavaScriptLLC
Рекомендации по теме
Комментарии
Автор

I had never heard of the comma operator. Thanks for the video!

bmehder
Автор

Great video! I had to watch it several times and run the code myself to get the concepts. Love it! I don't think of using reduce() as often as I should. Thank you and much appreciated!!!

TillmanTech
Автор

I always learn something new in your videos. thanks

ketankulkarni
Автор

Nullish coalescing operator, it works with logical or ||... And it also works with logical And??... If you want to understand this solution better go deeper with the coalescing operator. Nice video thanks 👍

josearmandozeballosduran
Автор

Great tutorial. This could be done also with ES5 methods like for loop.

Uncaught_in_promise
Автор

scores.reduce((accVal, val) => ({...accVal, [val]:++accVal[val] || 1}), {});

Without comma operator...

magnusfohlstrom
Автор

Somebody help me in this problem
Please write solution in javascript

Write a function called do_allocation(number_of_people, number_of_buses)

The function should return a list of number of people who can get into the next bus that comes in based on the following logic:

Each bus’s capacity is the sum of the capacities of the previous two buses.

Once all the people get in, then the buses can continue, but will have 0 people inside it.

This is the case when the number of people are less and there are more buses. So after all the people are already boarded, then the remaining buses will have 0 people boarding.

The output of the function is an array/list with the same length as number_of_buses.

The total of this output array/list should be less than or equal to the number_of_people.

The first bus’ capacity can be set to 1 by default.


E.g.


Def  do_allocation(number_of_people, number_of_buses):

      …. Your code….
    Return array[number of people got into first bus, number of people got into second bus, …., number of people who got into last bus]

coder-webdev