DEV Community

Haku B.
Haku B.

Posted on • Edited on

JS Edabit solution notebook

Return month long name based on number input

function monthName(num) {
    return new Date(2000, num - 1).toLocaleString("en-us", {month: "long"});
}
Enter fullscreen mode Exit fullscreen mode

Return first & last item in an array

function firstLast(arr) {
    return [arr.shift(), arr.pop()]
}
Enter fullscreen mode Exit fullscreen mode

When comparing strings and characters, includes() is case-sensitive.


Count matching char in a string (case-sensitive)

function charCount(myChar, str) {
    return [...str].filter(x => x===myChar).length;
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)