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)
Day 2
const allLongestStrings = a => a.filter(i => i.length === Math.max(...(a.map(a => a.length))))
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)
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)
Day 4
const arrayReplace = (arr, o, n) => arr.map(e => e === o ? n : e)
Day 5
const caseInsensitivePalindrome = (s) => s.toLowerCase().replace(/[\W\_]/g, '') === s.toLowerCase().replace(/[\W\_]/g, '').split('').reverse().join('')
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;
Top comments (0)