Alternating Sums
JavaScript
const alternatingSums = array => {
let team1 = 0, team2 = 0
array.forEach((num, index) => {
if(index % 2 === 0) team1 += num
else team2 += num
})
return [team1, team2]
}
/*
// OR METHOD 2
*/
const alternatingSums = array => {
let team1 = [], team2 = []
array.forEach((num, index) => {
if(index % 2 === 0) team1.push(num)
else team2.push(num)
})
team1 = team1.reduce((a,b) => a + b, 0)
team2 = team2.reduce((a,b) => a + b, 0)
return [team1, team2]
}
Also in JavaScript:
- Title
- dynsmic calss in react add
- Category
- JavaScript
- Title
- how to open new tab in vscode using keyboard
- Category
- JavaScript
- Title
- angular @Output()
- Category
- JavaScript
- Title
- add class jquery
- Category
- JavaScript
- Title
- how to print to console javascript
- Category
- JavaScript
- Title
- comment obtenir l'élément parent javascript
- Category
- JavaScript
- Title
- eval in js
- Category
- JavaScript
- Title
- callback in response node.js
- Category
- JavaScript
- Title
- javascript bind event to created element
- Category
- JavaScript
- Title
- array methods in javascript
- Category
- JavaScript
- Title
- javascript check if array is empty
- Category
- JavaScript
- Title
- angular 8 to 9
- Category
- JavaScript
- Title
- funcion dentro de objeto
- Category
- JavaScript
- Title
- export apk react native
- Category
- JavaScript
- Title
- how to check if something is array javascript
- Category
- JavaScript
- Title
- .join javascript
- Category
- JavaScript
- Title
- bubble sort javascript
- Category
- JavaScript
- Title
- How to append to a file in Node?
- Category
- JavaScript
- Title
- bash parse json
- Category
- JavaScript
- Title
- get value onChange from mat-select angular
- Category
- JavaScript
- Title
- download image in nodejs
- Category
- JavaScript
- Title
- javascript array flat
- Category
- JavaScript
- Title
- how to add headers to the server response node js
- Category
- JavaScript
- Title
- angular ngclass
- Category
- JavaScript
- Title
- how to print console in javascript
- Category
- JavaScript
- Title
- clone a JavaScript object
- Category
- JavaScript
- Title
- extend react.component
- Category
- JavaScript
- Title
- create array with specific size javascript
- Category
- JavaScript
- Title
- elasticsearch test node.js
- Category
- JavaScript
- Title
- console.log javascript
- Category
- JavaScript
- Title
- Javascript clear canvas
- Category
- JavaScript
- Title
- accept 2 values after decimal in angular forms
- Category
- JavaScript
- Title
- Elements in iteration expect to have 'v-bind:key' directives
- Category
- JavaScript
- Title
- integers to space separated string in javascript
- Category
- JavaScript
- Title
- box shadow javascript style change
- Category
- JavaScript
- Title
- access angular app outside localhost
- Category
- JavaScript
- Title
- check if string is datestring javascript
- Category
- JavaScript
- Title
- assign values to a table from javascript in VF page
- Category
- JavaScript
- Title
- ascii to char in javascript
- Category
- JavaScript
- Title
- get value of hidden field jquery
- Category
- JavaScript
- Title
- how to check if a string has only alphabets in javascript
- Category
- JavaScript
- Title
- google auth.onstatechange
- Category
- JavaScript
- Title
- chart js rotating the x axis labels
- Category
- JavaScript
- Title
- express url redirect
- Category
- JavaScript
- Title
- How to uninstall npm modules in node js?
- Category
- JavaScript
- Title
- autocomplete typeahead ajax
- Category
- JavaScript
- Title
- how to reload vscode
- Category
- JavaScript
- Title
- history.pushstate
- Category
- JavaScript
- Title
- append rotated triangle in anchor tag
- Category
- JavaScript
- Title
- get date one week from now javascript
- Category
- JavaScript
- Title
- format a date moment
- Category
- JavaScript
- Title
- add countdown timer to javascript quiz
- Category
- JavaScript
- Title
- jason rpc reactjs
- Category
- JavaScript
- Title
- define a route with path paramters in nodejs
- Category
- JavaScript
- Title
- alert user javascript
- Category
- JavaScript
- Title
- how to add a class to html using javascript
- Category
- JavaScript
- Title
- Better Array check with Array.isArray Because arrays are not true array in JavaScript, there is no simple typeof check. No problem! Use the method Array.isArray to check…
- Category
- JavaScript
- Title
- email regex
- Category
- JavaScript
- Title
- create new node project
- Category
- JavaScript
- Title
- how to link javascript to html
- Category
- JavaScript
- Title
- add 2 class names react
- Category
- JavaScript
- Title
- async fetch api call
- Category
- JavaScript
- Title
- Angularjs datetime
- Category
- JavaScript
- Title
- how to set up a json file
- Category
- JavaScript
- Title
- how to deploy react app in tomcat server
- Category
- JavaScript
- Title
- javascript .firstordefault
- Category
- JavaScript
- Title
- delete from array based on value javascript
- Category
- JavaScript
- Title
- close exit app react native
- Category
- JavaScript
- Title
- check if var is array js
- Category
- JavaScript
- Title
- angular cli create component
- Category
- JavaScript
- Title
- how to use a fixed time zone in nodejs
- Category
- JavaScript
- Title
- how to attach javascript to html
- Category
- JavaScript
- Title
- .includes javascript
- Category
- JavaScript
- Title
- how to get the value in a tag in react
- Category
- JavaScript
- Title
- async await anonymous function
- Category
- JavaScript
- Title
- gitignore for angular
- Category
- JavaScript
- Title
- check element exist in jquery
- Category
- JavaScript
- Title
- change text of element js
- Category
- JavaScript
- Title
- how to play sound on load js
- Category
- JavaScript
- Title
- angular npx
- Category
- JavaScript
- Title
- fizzbuzz js
- Category
- JavaScript
- Title
- for each js
- Category
- JavaScript
- Title
- if mousepressed javascript
- Category
- JavaScript
- Title
- async axios call
- Category
- JavaScript
- Title
- convert date to string javascript
- Category
- JavaScript
- Title
- how to push values in array
- Category
- JavaScript
- Title
- how to make fizzbuzz in javascript
- Category
- JavaScript
- Title
- check the doc name in javascript
- Category
- JavaScript
- Title
- how to define variable in javascript
- Category
- JavaScript
- Title
- how to print date like 10-may-2018 in javascript
- Category
- JavaScript
- Title
- getelementbyid
- Category
- JavaScript
- Title
- assign this value or if it is undefined this other value javascript
- Category
- JavaScript
- Title
- angular file upload app with django
- Category
- JavaScript
- Title
- Encrypt in PHP openssl and decrypt in javascript CryptoJS
- Category
- JavaScript
- Title
- create array from htmlcollection
- Category
- JavaScript
- Title
- angular event scroll end of page
- Category
- JavaScript
- Title
- convert a int to a unicode javascript
- Category
- JavaScript
- Title
- javascript assertequals
- Category
- JavaScript
- Title
- how to create a object in javascript
- Category
- JavaScript
- Title
- javascript add listeners to class
- Category
- JavaScript