Skip to content

Commit

Permalink
Homeworks-2: task 2 has been completed
Browse files Browse the repository at this point in the history
  • Loading branch information
dtr200 committed Jun 15, 2021
1 parent c3d6f31 commit bf5a574
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions homework-lecture-2/sequence-type.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,60 @@
function getSequenceType(list){
if(!list.length)
return
if(!list.length) return;

let prev = list[0];
let type = {
constant: false,
ascending: false,
weaklyAscending: false,
descending: false,
weaklyDescending: false
};

for(let i = 1; i < list.length; i++){
if(list[i] >= prev)
if(list[i] > prev &&
!type.descending &&
!type.weaklyAscending &&
!type.weaklyDescending &&
!type.constant){
type.ascending = true;
prev = list[i];
}
else if(list[i] < prev &&
!type.weaklyAscending &&
!type.weaklyDescending &&
!type.ascending &&
!type.constant){
type.descending = true;
prev = list[i];
}
else if(list[i] === prev &&
!type.descending &&
!type.ascending &&
!type.weaklyAscending &&
!type.weaklyDescending){
type.constant = true;
prev = list[i];
}
else if(list[i] >= prev &&
!type.descending &&
!type.weaklyDescending){
type.weaklyAscending = true;
prev = list[i];
}
else if(list[i] <= prev &&
!type.ascending &&
!type.weaklyAscending){
type.weaklyDescending = true;
prev = list[i];
}
else{
return 'RANDOM';
}
}
return type.weaklyAscending ? 'WEAKLY ASCENDING' :
type.weaklyDescending ? 'WEAKLY DESCENDING' :
type.ascending ? 'ASCENDING' :
type.descending ? 'DESCENDING' : 'CONSTANT'
}

getSequenceType([
Expand Down

0 comments on commit bf5a574

Please sign in to comment.