Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function printReverse(arr) {
- return arr.reverse();
- }
- printReverse([1,2,3,4]);
- // Refactor to print on new line
- function printReverse(arr){
- for(var i = arr.length - 1; i >= 0; i--) {
- console.log(arr[i]);
- }
- }
- printReverse([1,2,3,4]);
- //** isUniform **//
- function isUniform(array) {
- for(var i = 0; i < array.length -1; i++) {
- if(array[i] !== array[i + 1]) {
- return false;
- }
- }
- return true;
- }
- //** sumArray **//
- function sumArray(arr) {
- var sum = 0;
- arr.forEach(function(element){
- sum += element;
- });
- return sum;
- }
- //** max **//
- function max(arr) {
- var maxValue = 0;
- arr.forEach(function(element){
- if (maxValue < element) {
- maxValue = element;
- }
- });
- return maxValue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement