Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. function printReverse(arr) {
  2. return arr.reverse();
  3. }
  4. printReverse([1,2,3,4]);
  5.  
  6. // Refactor to print on new line
  7. function printReverse(arr){
  8. for(var i = arr.length - 1; i >= 0; i--) {
  9. console.log(arr[i]);
  10. }
  11. }
  12. printReverse([1,2,3,4]);
  13.  
  14. //** isUniform **//
  15.  
  16. function isUniform(array) {
  17. for(var i = 0; i < array.length -1; i++) {
  18. if(array[i] !== array[i + 1]) {
  19. return false;
  20. }
  21. }
  22. return true;
  23. }
  24.  
  25. //** sumArray **//
  26.  
  27. function sumArray(arr) {
  28. var sum = 0;
  29. arr.forEach(function(element){
  30. sum += element;
  31. });
  32. return sum;
  33. }
  34.  
  35. //** max **//
  36.  
  37. function max(arr) {
  38. var maxValue = 0;
  39. arr.forEach(function(element){
  40. if (maxValue < element) {
  41. maxValue = element;
  42. }
  43. });
  44. return maxValue;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement