Get the closest value for combinations of an array (JS)
问题 I'm looking for an algorithm that I can use for combining values in array, to get as close as possible to "another value". For instance, the number I want to find out what combination that gives the closes result to is 2.5. And my array is [0.5, 1.0, 1.5, 2.0, 3.0] . The combination in this case would be 2.0+0.5 . 2.7 would yield the same combo (2.5 is the closest), while 3.7 would yield 3.0+0.5 and 7.0 would be 3.0+3.0+1.0 . I've been reading up on different algorithms to create available