Skip to content

Commit

Permalink
Homework-2: Task 4 has been completed
Browse files Browse the repository at this point in the history
  • Loading branch information
dtr200 committed Jun 15, 2021
1 parent 6109e2f commit ce13d35
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions homework-lecture-2/biggest-heighbor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function getBiggestNeighbors(list){
const values = list.split(' ')
.map(num => Number(num));

let counter = 0;
for(let i = 1; i < values.length -1; i++){
if(values[i] > values[i - 1] && values[i] > values[i + 1])
counter++;
}
return `${counter}`;
}

getBiggestNeighbors('1 2 3 4 5');
getBiggestNeighbors('5 4 3 2 1');
getBiggestNeighbors('1 5 1 5 1');

0 comments on commit ce13d35

Please sign in to comment.