Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- /**
- * Найти пропущеное значение в неотсортированном массиве.
- * @param {number[]} values
- * @return {boolean}
- */
- function missing(values) {
- let min = Math.min(...values);
- let max = Math.max(...values);
- let all = Array.from(Array(max - min + 1), (e, i) => i + min);
- return all.filter(e => !values.includes(e)).join();
- }
- console.log(missing([1, 4, 3])); // 2
- console.log(missing([5, 1, 4, 2])); // 3
- console.log(missing([1, 2, 3, 4])); // undefined
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">/**
- * Найти пропущеное значение в неотсортированном массиве.
- * @param {number[]} values
- * @return {boolean}
- */
- function missing(values) {
- let min = Math.min(...values);
- let max = Math.max(...values);
- let all = Array.from(Array(max - min + 1), (e, i) => i + min);
- return all.filter(e => !values.includes(e)).join();
- }
- console.log(missing([1, 4, 3])); // 2
- console.log(missing([5, 1, 4, 2])); // 3
- console.log(missing([1, 2, 3, 4])); // undefined</script></body>
- </html>
Add Comment
Please, Sign In to add comment