Question: I want to implement efficiently "streaming Knapsack" problem in java.

The problem is I have a stream input of integer data coming continuously for example -1, 2, 9, 5, 5, 11, 1 -3,... 

The question is to find the first "k" elements in which their sum is "n>0". for example k=3 and n=12, then the solution is: ...,2,...,5, 5.

What is the efficient algorithm for it?

Answer: 
Solution for browsers which support [`Array.map()`](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map):

```
var result = arr.map(function(o) { return [+o.myId, o.myName]; });

```

For compatibility you may use the [shim](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map#Compatibility) provided at **MDN**.
The following should do the trick:

```
var myVar2 = [];
for (var i = 0; i < myVar1; i++) {
  myVar2.push([myVar1[i].myId, myVar1[i].myName]);
}

```