Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
const testCases = [
  ['1', true],
  ['1234', true],
  ['1221', true],
  ['3333', true],
  ['143332', true],
  ['22234', true],
  ['2234', true],
  ['22214', true],
  ['1221441', true],
  ['41233', true],
  ['13', false],
  ['1224', false],
  ['121', false],
  ['12221', false],
  ['43221', false]
];
const golf = s=>!/13|24|31|42|3(2|4)\11|4(1|3)\22|1(2|4)\33|2(1|3)\44|(.).\5/.test(s.replace(/(.)(\1\1)+/g,"$1"));
testCases.forEach(c => {
  let e = c[1];
  let a = golf(c[0]);
  
  console.log(c[0] + ': ' + (a === e ? 'pass' : `fail (expected ${e}, got ${a})`));
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers