Guest User

Untitled

a guest
Jan 15th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. /**
  12. * Найти пропущеное значение в неотсортированном массиве.
  13. * @param {number[]} values
  14. * @return {boolean}
  15. */
  16. function missing(values) {
  17. let min = Math.min(...values);
  18. let max = Math.max(...values);
  19. let all = Array.from(Array(max - min + 1), (e, i) => i + min);
  20. return all.filter(e => !values.includes(e)).join();
  21. }
  22.  
  23. console.log(missing([1, 4, 3])); // 2
  24. console.log(missing([5, 1, 4, 2])); // 3
  25. console.log(missing([1, 2, 3, 4])); // undefined
  26. </script>
  27.  
  28.  
  29.  
  30. <script id="jsbin-source-javascript" type="text/javascript">/**
  31. * Найти пропущеное значение в неотсортированном массиве.
  32. * @param {number[]} values
  33. * @return {boolean}
  34. */
  35. function missing(values) {
  36. let min = Math.min(...values);
  37. let max = Math.max(...values);
  38. let all = Array.from(Array(max - min + 1), (e, i) => i + min);
  39. return all.filter(e => !values.includes(e)).join();
  40. }
  41.  
  42. console.log(missing([1, 4, 3])); // 2
  43. console.log(missing([5, 1, 4, 2])); // 3
  44. console.log(missing([1, 2, 3, 4])); // undefined</script></body>
  45. </html>
Add Comment
Please, Sign In to add comment