DEV Community

Saif Al Siam
Saif Al Siam

Posted on

#100daysofcode [Day - 02]

100daysofcode [Day - 02]

Today I've solved some small problems.
01 Getting Leap-year,
02 Find the Biggest Number from an Array,
03 Remove the Duplicate Name or Numbers,
04 Getting the Factorial numbers
Alt TextAlt TextAlt TextAlt Text

coding #javascript #webdevelopment

Discussion (4)

Collapse
lukeshiru profile image
LUKESHIRU

There are shorter versions for every function, if you're interested:

const dedupe = array => [...new Set(array)];
const biggest = array => array.sort((a, b) => b - a)[0];
const factorial = number => number < 2 ? 1 : number * factorial(number - 1);
const leapYear = year => year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
Enter fullscreen mode Exit fullscreen mode
  • dedupe: We spread a newly created Set (which dedupes by nature).
  • biggest: We sort from biggest to smalles and get the first element.
  • factorial: Recursive version.
  • leapYear: Is always better to just return a boolean (return logic) instead of doing doing an if (if (logic) { return true; } else { return false; }).

Cheers!

Collapse
alsiam profile image
Saif Al Siam Author

love from heart bro.
actually, trying do my best as a beginner

Collapse
lukeshiru profile image
LUKESHIRU

One of the most important things is to take feedback with love, and you're doing just that. Keep at it and you'll never stop growing ❤️

Thread Thread
alsiam profile image
Saif Al Siam Author

❤️❤️❤️