Clever! I'll accept it for the normal challenge :)
If you want hard mode though, I think you'll have to show an implementation of .filter that doesn't use if, ?:, ||, &&, ?., or ??. (I'll allow .reduce to be used though, as well as .map)
Okay, well, my next solution is probably not what you were expecting. It builds on the idea that a boolean can be used as a number. I think it meets the hardcore requirements.
constisFizz=n=>n%3===0constisBuzz=n=>n%5===0constisNeither=n=>!isFizz(n)&&!isBuzz(n)// the magic:constoptional=(f,x)=>Array(Number(f(x))).fill(x)constfizzbuzz=n=>{constfizz=optional(isFizz,n).map(_=>'Fizz')constbuzz=optional(isBuzz,n).map(_=>'Buzz')constnum=optional(isNeither,n).map(String)return`${fizz.join('')}${buzz.join('')}${num.join('')}`}
Clever! I'll accept it for the normal challenge :)
If you want hard mode though, I think you'll have to show an implementation of
.filter
that doesn't useif
,?:
,||
,&&
,?.
, or??
. (I'll allow.reduce
to be used though, as well as.map
)Well done, thanks for commenting!
Okay, well, my next solution is probably not what you were expecting. It builds on the idea that a boolean can be used as a number. I think it meets the hardcore requirements.
Very nice! I think you have met the hardcore requirements.
And I think slightly less code than my functional solution will be, well done!