Advertisement
wrequiems

Untitled

May 14th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let removeMaximum = (array) => {
  2.     // find maximum in array and it's index
  3.     let maximum = 0;
  4.     for (let i = 0; i < array.length; i++) {
  5.         if (maximum < array[i]) {
  6.             maximum = array[i];
  7.         }
  8.     }
  9.  
  10.     // remove 1 element of value maximum
  11.     array = array.filter(function(value, index, arr){
  12.         return value !== maximum;
  13.     });
  14.     return array;
  15. }
  16.  
  17. let a = [1, 2, 3, 10, 5, 100, 8, 15];
  18. let arrayWithoutMaximum = removeMaximum(a);
  19. console.log(arrayWithoutMaximum);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement