2015-05-05

JavaScript - Return all addend combinations of a target value, from an array

Use this library (single .js file)... 
https://github.com/falconerandloillc/addends


(1) Run this...

console.log( getAddends( 12, [-2.3,-1,1,2.3,2.4] ) );



(2) Returns (to the browser's console):

Object
array: Array[10]
   0: -2.3
   1: -1
   2: 1
   3: 2.3
   4: 2.4
   length: 5
combinations: Array[3]
   0: "1,2,3,6"
   1: "1,2,4,5"
   2: "1,2,9"
   length: 3
dataType: "integer"
iterations: 66
precision: 2
target: 12
time: 3


No comments:

Post a Comment