hw11_04_insorted.html 423 B

123456789101112131415161718
  1. <head>insorted</head>
  2. <body>
  3. <script>
  4. let inSorted = (...args) => {
  5. let prevVal = null;
  6. for (el of args) {
  7. if (prevVal != null && prevVal > el)
  8. return false;
  9. prevVal = el
  10. }
  11. return true;
  12. }
  13. console.log(inSorted(1, 2, 3, 6, 8));
  14. console.log(inSorted(1, 2, 3, 2, 8));
  15. </script>
  16. </body>