fork download
  1.  
  2.  
  3. // your code goes here
  4. function processData(input) {
  5. const ipAddresses = input.split('\n').slice(1);
  6. const regex = {
  7. ipv4: /^((1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])$/,
  8. ipv6: /^([\da-f]{1,4}:){7}[\da-f]{1,4}$/
  9. }
  10. const answer = ipAddresses.map(ipaddr =>
  11. regex.ipv4.test(ipaddr) ? 'IPv4' :
  12. regex.ipv6.test(ipaddr) ? 'IPv6' : 'Neither'
  13. );
  14. console.log(answer.join('\n'));
  15. }
  16.  
  17. process.stdin.resume();
  18. process.stdin.setEncoding("ascii");
  19. _input = "";
  20. process.stdin.on("data", function (input) {
  21. _input += input;
  22. });
  23.  
  24. process.stdin.on("end", function () {
  25. processData(_input);
  26. });
  27.  
Success #stdin #stdout 0.04s 146944KB
stdin
this is junk text.
127.0.0.1
255.vvv.3.3
stdout
IPv4
Neither