JavaScript Problem: Counting Duplicate Elements in an Array

  Рет қаралды 11,281

All Things JavaScript, LLC

All Things JavaScript, LLC

Күн бұрын

Пікірлер: 23
@bmehder
@bmehder 2 жыл бұрын
I had never heard of the comma operator. Thanks for the video!
@AllThingsJavaScript
@AllThingsJavaScript 2 жыл бұрын
Glad to help
@ketankulkarni2675
@ketankulkarni2675 2 жыл бұрын
I always learn something new in your videos. thanks
@AllThingsJavaScript
@AllThingsJavaScript 2 жыл бұрын
Glad to hear it!
@TillmanTech
@TillmanTech 2 жыл бұрын
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!!!
@AllThingsJavaScript
@AllThingsJavaScript 2 жыл бұрын
Glad it was helpful!
@aabirsabil4393
@aabirsabil4393 Жыл бұрын
Great video
@sairamn2863
@sairamn2863 2 жыл бұрын
Great content sir.. very helpful 🎉😊
@mariummagdy4359
@mariummagdy4359 2 жыл бұрын
thank you so much
@AllThingsJavaScript
@AllThingsJavaScript 2 жыл бұрын
Welcome 😊
@josearmandozeballosduran7086
@josearmandozeballosduran7086 2 жыл бұрын
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 👍
@Adel_Gs
@Adel_Gs Жыл бұрын
👌🏻👌🏻✅ Bravo
@Uncaught_in_promise
@Uncaught_in_promise 2 жыл бұрын
Great tutorial. This could be done also with ES5 methods like for loop.
@AllThingsJavaScript
@AllThingsJavaScript 2 жыл бұрын
Yes, definitely
@magnusfohlstrom
@magnusfohlstrom 2 жыл бұрын
scores.reduce((accVal, val) => ({...accVal, [val]:++accVal[val] || 1}), {}); Without comma operator...
@AllThingsJavaScript
@AllThingsJavaScript 2 жыл бұрын
Love it!!
@coder-webdev5907
@coder-webdev5907 2 жыл бұрын
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]
@AllThingsJavaScript
@AllThingsJavaScript 2 жыл бұрын
The number of people per bus sounds like solving a fibonacci sequence: kzbin.info/www/bejne/pJi2ZpSQi9Kkpc0 Once you have that down I think the other parts can be figured out. See if that tutorial helps.
@coder-webdev5907
@coder-webdev5907 2 жыл бұрын
@@AllThingsJavaScript I solved this like that it is nice way or how can i make it easy to understand .? // Number of People and Number of Buses let person, buses; // i = number of iterations when passengers are not in the bus // j = number of iterations when passengers are less than the next sum // n1 = passengers in the first bus // n2 = passengers in the first bus // sum = n1 + n2 // total = number of passengers boarded // exceedLim = total number exceeding real numbers of passengers let i, j, n1 = 1, n2 = 1, sum, total = 1, exceedLim; const resultArray = [1]; // Result Array with (1st bus capacity = 1). // Function to provide elements to Result Array const do_Allocation = (person, buses) => { // For loop for passengers to get into the bus with complete sum for (i = 1; i < buses; i++) { sum = n1 + n2; // sum of first two buses' passenger count total += n2; // total number of passengers onboard n1 = n2; // changing the first bus identity to second bus n2 = sum; // changing the second bus identity to the next bus resultArray[i] = n1; // insertion of passenger count in the bus exceedLim = total + n2; // keeping track of sum exceeding the people // if sum exceeds then iterations stop to proceed into the // incomplete sum array insertions if (exceedLim > person) { break; }; }; // For loop for passengers to get into the bus with incomplete sum for (j = i+1; j < buses; j++) { if (j==i+1) { // insertion of rest passenger on the bus resultArray[j] = person - total; } else { // insertion of the wmpty bus value, i.e. 0 in the empty buses resultArray[j] = 0; }; }; return resultArray; }; // call the function with people and buses attributes console.log('Result Array: ' + do_Allocation(70, 13));
@AllThingsJavaScript
@AllThingsJavaScript 2 жыл бұрын
@@coder-webdev5907 Great job solving the problem! These types of problems are a great way to learn code.
@caseyjody9898
@caseyjody9898 2 жыл бұрын
Hard to understand
@caseyjody9898
@caseyjody9898 2 жыл бұрын
This accval confused me alot
JavaScript Problem: Explaining Eloquent JavaScript's Matrix Class
21:57
All Things JavaScript, LLC
Рет қаралды 1,3 М.
JavaScript Problem: Removing Duplicate Objects from an Array
9:50
All Things JavaScript, LLC
Рет қаралды 24 М.
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
JavaScript Tip: 7 Ways to Iterate Over an Array
15:11
All Things JavaScript, LLC
Рет қаралды 9 М.
JavaScript Problem: Searching an Array for a Value
13:43
All Things JavaScript, LLC
Рет қаралды 38 М.
Reduce: 10 Different Examples. JavaScript Fundamentals.
26:57
Leigh Halliday
Рет қаралды 29 М.
JavaScript Problem: Combining and Sorting Objects in an Array
21:39
All Things JavaScript, LLC
Рет қаралды 4,9 М.
JavaScript Problem: Comparing Two Arrays without Loops
13:46
All Things JavaScript, LLC
Рет қаралды 16 М.
Constructors Are Broken
18:16
Logan Smith
Рет қаралды 122 М.
Learn JavaScript Array Reduce In 10 Minutes
10:22
Web Dev Simplified
Рет қаралды 206 М.
JavaScript Problem: Extracting Numbers from a String
15:17
All Things JavaScript, LLC
Рет қаралды 9 М.
Rust Functions Are Weird (But Be Glad)
19:52
Logan Smith
Рет қаралды 153 М.
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН