codedamn

Unable to pass the test case.

Asked by Sahil Shendurkar about 3 months ago

0

https://codedamn.com/problem/fQ4iqU5za4yt8SlOPcWBf?challengeList=50-days-of-js

Return zero if there are fewer than three elements in the array. My test case is not passing. I am not getting what is wrong

1 Answer

    0
    	return arr.reduce((acc, curr, index) => {
    	  if ((index + 1) % 3 === 1) {
    		return acc + curr;
    	  } else {
    		return acc;
    	  }
    	}, 0);
      };
    
    console.log(sumOfThirds([-5, 0, 5, -4, 1, 6, -3, 2, 7]))```
    
    Let me know if the code is confusing
    
    @parmjeetmishra

    Parmjeet Mishra

    @parmjeetmishra

Your answer