Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's similar code written in JavaScript</p> <pre><code>var nric = []; nric.multiples = [ 2, 7, 6, 5, 4, 3, 2 ]; nric.isNricValid = function (theNric) { if (!theNric || theNric == '') { return false; } if (theNric.length != 9) { return false; } var total = 0 , count = 0 , numericNric; var first = theNric[0] , last = theNric[theNric.length - 1]; if (first != 'S' &amp;&amp; first != 'T') { return false; } numericNric = theNric.substr(1, theNric.length - 2); if (isNaN(numericNric)) { return false } while (numericNric != 0) { total += (numericNric % 10) * nric.multiples[nric.multiples.length - (1 + count++)]; numericNric /= 10; numericNric = Math.floor(numericNric); } var outputs; if (first == 'S') { outputs = [ 'J', 'Z', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A' ]; } else { outputs = [ 'G', 'F', 'E', 'D', 'C', 'B', 'A', 'J', 'Z', 'I', 'H' ]; } return last == outputs[total % 11]; } nric.isFinValid = function(fin) { if (!fin || fin == '') { return false; } if (fin.length != 9) { return false; } var total = 0 , count = 0 , numericNric; var first = fin[0] , last = fin[fin.length - 1]; if (first != 'F' &amp;&amp; first != 'G') { return false; } numericNric = fin.substr(1, fin.length - 2); if (isNaN(numericNric)) { return false; } while (numericNric != 0) { total += (numericNric % 10) * nric.multiples[nric.multiples.length - (1 + count++)]; numericNric /= 10; numericNric = Math.floor(numericNric); } var outputs; if (first == 'F') { outputs = [ 'X', 'W', 'U', 'T', 'R', 'Q', 'P', 'N', 'M', 'L', 'K' ]; } else { outputs = [ 'R', 'Q', 'P', 'N', 'M', 'L', 'K', 'X', 'W', 'U', 'T' ]; } return last == outputs[total % 11]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload