DEV Community

Discussion on: Day 04: 30 Days of Codewars.js

Collapse
 
ogzhanolguncu profile image
Oğuzhan Olguncu • Edited

Solution for your first kata can be shortened as

const solution = num =>
  num.reduce((acc, elm) => acc + ((elm % 3 === 0 || elm % 5 === 0) && elm),  0)

Collapse
 
youssefrabeiii profile image
Youssef Rabei

Thanks, it did improve the time complexity too

Collapse
 
ogzhanolguncu profile image
Oğuzhan Olguncu

Shortened it even more. Cheers.

Collapse
 
youssefrabeiii profile image
Youssef Rabei • Edited

I just tried to submit it but it didn't work

Collapse
 
ogzhanolguncu profile image
Oğuzhan Olguncu

I have not checked the kata, but my solution assumes given parameter is Array. That might be the source of your problem.

Thread Thread
 
youssefrabeiii profile image
Youssef Rabei

I guessed that and it's one of the problems and i fixed it by transform the given number to an array of digits and then run your code over it but it returned 0