JavaScript/7kyu/Sorted_yes_no_how.js
// You can assume the array will always be valid, and there will always be one correct answer.
You can assume the array will always be valid, and there will always be one correct answer.
You can assume the array will always be valid and there will always be one correct answer .
function isSortedAndHow(array) {
  let sort = 'asc';
  for(let i = 0; i < array.length - 1; i++) {
    if (array[i] > array[i + 1]) {
      sort = 'no';
      break;
    }
  }
  if (sort === 'asc') {
    return 'yes, ascending';
  } else {
    sort = 'desc'
    for(let i = 0; i < array.length - 1; i++) {
      if (array[i] < array[i + 1]) {
        sort = 'no';
        break;
      }
    }
  }
  return (sort === 'desc') ? 'yes, descending' : 'no';
}
function isSortedAndHow ( array ) { let sort = 'asc' ; for ( let i = 0 ; i < array . length - 1 ; i ++ ) { if ( array [ i ] > array [ i + 1 ] ) { sort = 'no' ; break ; } } if ( sort === 'asc' ) { return 'yes, ascending' ; } else { sort = 'desc' for ( let i = 0 ; i < array . length - 1 ; i ++ ) { if ( array [ i ] < array [ i + 1 ] ) { sort = 'no' ; break ; } } } return ( sort === 'desc' ) ? 'yes, descending' : 'no' ; }
You can assume the array will always be valid, and there will always be one correct answer.
You can assume the array will always be valid and there will always be one correct answer .