Generation

generate functionThu, 17 Nov 2022

calculate a number of all possible combinations from an array of numbers

function combinations(arr) { let array = [] for (let i = 0; i < arr.length; i++) { for (let j = 0; j < arr.length; j++) { array.push(arr[i] + arr[j]); } } return array; } combinations([1, 2, 3, 4, 5])

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant