Guest User

Untitled

a guest
Jan 12th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. // Simplify version
  2.  
  3. // Itterative
  4. function max1(list){
  5. var result = -Infinity;
  6. for (var i = 0; i < list.length; i++) {
  7. result <= list[i] && (result = list[i]);
  8. }
  9. return result;
  10. }
  11.  
  12. document.write(max1([-1,-2,-3,1,2,3]))
  13.  
  14. // Recursive
  15. function max(list, max_value) {
  16. max_value = max_value || -Infinity;
  17. if (list.length != 0) {
  18. return max(list.slice(1), (list[0] > max_value ? list[0] : max_value));
  19. } else {
  20. return max_value;
  21. }
  22. }
  23.  
  24. document.write(max([-1,-2,-3,1,2,3]))
Add Comment
Please, Sign In to add comment