Created
March 12, 2018 14:23
-
-
Save Nditah/e83003f364223773bf524fd5ffcb6d29 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/lebimik
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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"> | |
| /* | |
| Given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A. | |
| For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5. | |
| Given A = [1, 2, 3], the function should return 4. | |
| Given A = [−1, −3], the function should return 1. | |
| each element of array A is an integer within the range [−1,000,000..1,000,000]. | |
| */ | |
| function solution(A = []) { | |
| let set = new Set(A); | |
| for(let i = 1; i < 1000000; i++){ | |
| if(set.has(i) === false) { | |
| return i; | |
| } | |
| } | |
| } | |
| A = [-1, -3]; | |
| console.log(solution(A)); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">/* | |
| Given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A. | |
| For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5. | |
| Given A = [1, 2, 3], the function should return 4. | |
| Given A = [−1, −3], the function should return 1. | |
| each element of array A is an integer within the range [−1,000,000..1,000,000]. | |
| */ | |
| function solution(A = []) { | |
| let set = new Set(A); | |
| for(let i = 1; i < 1000000; i++){ | |
| if(set.has(i) === false) { | |
| return i; | |
| } | |
| } | |
| } | |
| A = [-1, -3]; | |
| console.log(solution(A)); | |
| </script></body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A. | |
| For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5. | |
| Given A = [1, 2, 3], the function should return 4. | |
| Given A = [−1, −3], the function should return 1. | |
| each element of array A is an integer within the range [−1,000,000..1,000,000]. | |
| */ | |
| function solution(A = []) { | |
| let set = new Set(A); | |
| for(let i = 1; i < 1000000; i++){ | |
| if(set.has(i) === false) { | |
| return i; | |
| } | |
| } | |
| } | |
| A = [-1, -3]; | |
| console.log(solution(A)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment