Sum of all the multiples of 3 or 5
const findSum = n => {
let countArr = []
for(let i = 0; i <= n; i++) if(i % 3 === 0 || i % 5 === 0) countArr.push(i)
return countArr.reduce((acc , curr) => acc + curr)
}
console.log(findSum(5))const findSum = n => {
let countArr = []
for(let i = 0; i <= n; i++) countArr.push(i)
let finalArr = countArr.map(digit => {
if(digit % 3 === 0 || digit % 5 === 0) return digit
else return 0
}).reduce((acc , curr) => acc + curr)
return finalArr
}
console.log(findSum(10))
Also in JavaScript:
- less than or equal js
- what is adapter.js
- delay in javascript
- how to change package name in react native
- How many different types of JS alerts do we have?
- return value of confirm box in javascript
- js get base url
- wait time js
- export multiple functions react
- date.parse string to javascript
- watchman watch-del-all, and react-native start --reset-cache
- https with express
- reverse a linked list js
- node js catch any errors
- get value in maps loop using enzym
- javascript stringify an object
- flatten an array javascript
- javaascript all
- ERROR in ./node_modules/tns-core-modules/ui/core/view/view.js Module not found: Error: Can't resolve '@nativescript/core/ui/core/view/view' in '/home/deepali/projects/supersquad-client/node_modules/tns-core-modules/ui/core/view'
- $(this) option selected jquery
- parsley validation checkbox alignment
- javascript return promise
- RFC8259 json
- split the numbers js