import * as euler from 'euler.js' function trunc_l(n) { if (n < 10) return undefined; return Number(euler.digitize(n).slice(1).join('')); } function trunc_r(n) { if (n < 10) return undefined; var s = euler.digitize(n); return Number(s.slice(0,s.length-1).join('')); } var truncs = []; outer: for (var i = 10; i < 1000000; i++) { if (euler.isprime(i)) { var r = i; while (r = trunc_r(r)) if (!euler.isprime(r)) continue outer; var l = i; while (l = trunc_l(l)) if (!euler.isprime(l)) continue outer; truncs.push(i); } } console.log(truncs); console.log(truncs.reduce((a,v) => a += v));