Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Simplify version
- // Itterative
- function max1(list){
- var result = -Infinity;
- for (var i = 0; i < list.length; i++) {
- result <= list[i] && (result = list[i]);
- }
- return result;
- }
- document.write(max1([-1,-2,-3,1,2,3]))
- // Recursive
- function max(list, max_value) {
- max_value = max_value || -Infinity;
- if (list.length != 0) {
- return max(list.slice(1), (list[0] > max_value ? list[0] : max_value));
- } else {
- return max_value;
- }
- }
- document.write(max([-1,-2,-3,1,2,3]))
Add Comment
Please, Sign In to add comment