Skip to content

Commit

Permalink
Merge 5716752 into f6a021c
Browse files Browse the repository at this point in the history
  • Loading branch information
yefremov committed May 4, 2017
2 parents f6a021c + 5716752 commit 90392b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -2,14 +2,15 @@

This is a collection of different algorithms, written in JavaScript.
The purpose of this package is to define basic algorithms in a concise,
but readable form. However, no (pre)mature optimizations should be expected
but readable form. However, no (pre)mature optimizations should be expected
here and code should never be used in production.

## Contents

### Iterative

- [x] coprime
- [x] maxsubarray
- [x] prime

### Recursive
Expand Down
18 changes: 18 additions & 0 deletions lib/iterative/maxsubarray.js
@@ -0,0 +1,18 @@

/**
* Expose `maxsubarray`.
*/

module.exports = maxsubarray;

function maxsubarray(array) {
var maximum = 0;
var current = 0;

for (var i = 0; i < array.length; i++) {
current = Math.max(0, current + array[i]);
maximum = Math.max(maximum, current);
}

return maximum;
}

0 comments on commit 90392b9

Please sign in to comment.