diff options
Diffstat (limited to 'challenge-012/zapwai/javascript/ch-2.js')
| -rw-r--r-- | challenge-012/zapwai/javascript/ch-2.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-012/zapwai/javascript/ch-2.js b/challenge-012/zapwai/javascript/ch-2.js new file mode 100644 index 0000000000..fecd56d950 --- /dev/null +++ b/challenge-012/zapwai/javascript/ch-2.js @@ -0,0 +1,23 @@ +let input = `/a/b/c/d +/a/b/cd +/a/b/cc +/a/b/c/d/e`; + +function proc(input) { + let line = input.split("\n"); + let prefix = line[0]; + let cnt = 1; + while (cnt > 0) { + cnt = 0; + prefix = prefix.slice(0,prefix.lastIndexOf("/")); + for (let i = 0; i < line.length; i++) { + let pattern = new RegExp("^"+prefix+"/"); + if (!pattern.test(line[i])) { + cnt++; + } + } + } + return prefix; +} + +console.log(proc(input)) |
