Ad
Algorithms
Logic
Fundamentals

A Windows 95 cd key has ten digits, in the form of XXX-XXXXXXX.

The first segment (also named a site) must be 3 digits long, but cannot be 333, 444, 555, 666, 777, 888, or 999.

The second segment must be 7 digits long, divisble by 7, but the last digit can not be 0 or ≥ 8.

(adapted from this article)

function validateKey(key) {
  var segments = key.split('-');
  
  var illegalSites = [333, 444, 555, 666, 777, 888, 999];
  var illegalEnds = [0, 8, 9];
  
  if (segments.length != 2 
  || illegalSites.includes(+(segments[0])) || +(segments[0]) > 999 || +(segments[0]) < 0 || segments[0].length != 3
  || +(segments[1]) % 7 == true || illegalEnds.includes(+(segments[1].slice(-1))) || segments[1].length != 7) {return false}

  return true;
}