This Dot provides teams with technical leaders who bring deep knowledge of the web platform. We help teams set new standards, and deliver results predictably.
For this example it wouldn't make any difference to be honest. Map and ForEach both iterate the array and apply the given function, their difference is that ForEach doesn't return a value just iterates the array and executes the given function on the elements but map will return a new array with the modified array.
Usually people are using map when they want to achieve immutability (they don't want to modify their array but to return a modified copy)
Example:
letnums=[1,2,3];letresult=nums.forEach(n=>n*2);// here the result variable will be undefinedletresult=nums.map(n=>n*2)// here the result variable will be [2, 4, 6]
Thank you for your post it was very helpful. I added a method to determine the exact number of days for the number day in the calendar instead of 42 in generateCalendarDays and thought I would pass it on:
/**
Calculates the number of calendar days in a given month.
*
@param {Date} day - The date used to determine the month.
@return {number} The number of calendar days in the specified month.
*/
private getNumberOfCalendarDays(day: Date): number {
const mYear = day.getFullYear();
const mMonth = day.getMonth()+ 1;
const mFristDay = new Date(mYear, mMonth, 1).getDay();
const mLastDay = new Date(mYear, mMonth + 1, 0).getDay();
const mDaysFromLastMonth = mFristDay - 1 == -1 ? 6 : mFristDay - 1;
const mDaysFromNextMonth = 6 - mLastDay == -1 ? 0 : 6 - mLastDay;
const mDaysInMonth = new Date(mYear, mMonth + 1, 0).getDate();
return (mDaysFromLastMonth + mDaysInMonth + mDaysFromNextMonth) + 1;
}
Hi @pkhussain
sure you can use it as you like :) Just keep in mind that this is just a POC and might have bugs, I've never tested it thoroughly, so use with causion!
Hi there! I'm looking at your implementation but It currently seems like the left and right arrows are skipping/incorrectly setting the months. Do you know why this might be happening?
Thanks for your solution
Good job!
Thank you :)
You did great Ricky!
Many thanks :)
This piece of code here is so cool
weekDays.push(days)
if (++index % chunkSize === 0) {
calendarDays.push(weekDays);
weekDays = [];
}
Thank you herrigor, I hope you find it useful :)
Hi Ricky. It's awesome. Just wanted to know why we use map instead of foreach in pipe. Am new in angular
Hi surajKurade!
For this example it wouldn't make any difference to be honest. Map and ForEach both iterate the array and apply the given function, their difference is that ForEach doesn't return a value just iterates the array and executes the given function on the elements but map will return a new array with the modified array.
Usually people are using map when they want to achieve immutability (they don't want to modify their array but to return a modified copy)
Example:
Hope this helps!
Thanks Ricky 👍
Looks good man
Thank you Don, glad you like it!
This is amazing 🎉🎉
Very nice
Thank you for your post it was very helpful. I added a method to determine the exact number of days for the number day in the calendar instead of 42 in generateCalendarDays and thought I would pass it on:
/**
Great help!! Thanks :-)
Hi Ricky, Can we create room and meeting booking in your good calendar ?
Hi @pkhussain sure you can use it as you like :) Just keep in mind that this is just a POC and might have bugs, I've never tested it thoroughly, so use with causion!
Hi there! I'm looking at your implementation but It currently seems like the left and right arrows are skipping/incorrectly setting the months. Do you know why this might be happening?
Thank you for the code,
Is there any hint to like Monday, Tuesday, etc it in datatable?
I have difficulty to match the day just like on the calendar