DEV Community

Dominic Myers
Dominic Myers

Posted on • Originally published at drmsite.blogspot.com on

The 10-Day JavaScript Challenge

Yay! There's another one started, such fun!

I'll add to this is I go along.

Day 1

const add = (...a) => a.reduce((t, v) => t + v)
Enter fullscreen mode Exit fullscreen mode

Day 2

const allLongestStrings = a => a.filter(i => i.length === Math.max(...(a.map(a => a.length))))
Enter fullscreen mode Exit fullscreen mode

This is not overly efficient, but it works. Then I got to remembering about default values and altered it to this:

const allLongestStrings = (a, i = Math.max(...(a.map(a => a.length)))) => a.filter(e => e.length === i)
Enter fullscreen mode Exit fullscreen mode

Longer, but we only check for the longest string the once, rather than over each iteration.

Day 3

const allLongestStrings = (a, i = Math.max(...(a.map(a => a.length)))) => a.filter(e => e.length === i)
Enter fullscreen mode Exit fullscreen mode

Day 4

const arrayReplace = (arr, o, n) => arr.map(e => e === o ? n : e)
Enter fullscreen mode Exit fullscreen mode

Day 5

const caseInsensitivePalindrome = (s) => s.toLowerCase().replace(/[\W\_]/g, '') === s.toLowerCase().replace(/[\W\_]/g, '').split('').reverse().join('')
Enter fullscreen mode Exit fullscreen mode

I like this way because it deals with "A man, a plan, a canal, Panama!". But I really like this one (not mine):

const caseInsensitivePalindrome = s => [...s = s.toLowerCase()].reverse().join`` === s;
Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay