求和数组值,直到达到特定值并返回使用的值

时间:2014-09-23 14:38:54

标签: javascript arrays subset subset-sum

是否有一个函数可以使用一组数字和一个特定的数字来添加数组中的一些数字以获取特定数字并在数组中返回您使用的数字?

这方面的一个例子是:

var specificFunction = function(list, target){
    // some kind of code here that adds the numbers in the array till it gets the number you want and returns in a array the numbers it used to get the number you want
};
specificFunction([256,8,512,8192,32,1024,16,2], 9224); // [8192,1024,8]

如果没有这样的功能,我该如何制作呢?

如果有这样的功能,那么我在哪里可以找到它还是内置它?

0 个答案:

没有答案