Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

loop with multiple conditions js codesmith

const array1 = [1, 3, 5, 17, 15];
const array2 = [1, 2, 3, 4, 5];

function addingAllTheWeirdStuff(array1, array2) {

    const oddSum = array2.reduce((sum, current) => current % 2 ? current + sum : 0 + sum, 0)
    const oddEven = array2.reduce((sum, current) => current % 2 == 0 ? current + sum : 0 + sum, 0)

    return array1.map(num => num < 10 ? num + oddSum : num + oddEven)

}

console.log(addingAllTheWeirdStuff(array1, array2))
 Run code snippet
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #loop #multiple #conditions #js #codesmith
ADD COMMENT
Topic
Name
6+2 =