diff options
Diffstat (limited to 'challenge-284/zapwai/javascript/ch-1.js')
| -rw-r--r-- | challenge-284/zapwai/javascript/ch-1.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-284/zapwai/javascript/ch-1.js b/challenge-284/zapwai/javascript/ch-1.js new file mode 100644 index 0000000000..ced6b0c439 --- /dev/null +++ b/challenge-284/zapwai/javascript/ch-1.js @@ -0,0 +1,29 @@ +let ints = [2, 2, 3, 4]; +proc(ints); +ints = [1, 2, 2, 3, 3, 3]; +proc(ints); +ints = [1, 1, 1, 3]; +proc(ints); +function proc(ints) { + console.log("Input: ints =", ints); + let lucky = -1; + let max = 0; + for (let item of ints) { + if (max < item) { + max = item; + } + } + let freq = []; + for (let j = 0; j < 1 + max; j++) { + freq.push(0); + } + for (let item of ints) { + freq[item]++; + } + for (let i = 1; i < freq.length; i++) { + if (i == freq[i]) { + lucky = i; + } + } + console.log("Output:", lucky); +} |
