{"ScriptPreparationCode":null,"TestCases":[{"Name":"Sem recursividade","Code":"var cpf = \u002212345678901\u0022;\r\n\r\nfunction validateCPF(cpf) {\r\n cpf = cpf.replace(/\\D/g, \u0027\u0027);\r\n\r\n if (cpf.length != 11) {\r\n return false;\r\n }\r\n\r\n if (Number(cpf) - Number(Array(12).join(cpf[0])) === 0) {\r\n return false;\r\n }\r\n\r\n var rcpf1 = cpf.substring(0, 9);\r\n var rcpf2 = cpf.substring(9);\r\n var d1 = 0;\r\n for (var i = 0; i \u003C 9; i\u002B\u002B) {\r\n d1 \u002B= parseInt(rcpf1.charAt(i)) * (10 - i);\r\n }\r\n d1 = 11 - (d1 % 11);\r\n if (d1 \u003E 9) {\r\n d1 = 0;\r\n }\r\n if (parseInt(rcpf2.charAt(0)) != d1) {\r\n return false;\r\n }\r\n d1 *= 2;\r\n for (var j = 0; j \u003C 9; j\u002B\u002B) {\r\n d1 \u002B= parseInt(rcpf1.charAt(j)) * (11 - j);\r\n }\r\n d1 = 11 - (d1 % 11);\r\n if (d1 \u003E 9) {\r\n d1 = 0;\r\n }\r\n if (parseInt(rcpf2.charAt(1)) != d1) {\r\n return false;\r\n }\r\n\r\n return true;\r\n}\r\n\r\nvalidateCPF(cpf);","IsDeferred":false},{"Name":"Com recursividade","Code":"var cpf = \u002212345678901\u0022;\r\n\r\nfunction validateCPF(cpf) {\r\n\r\n cpf = cpf.replace(/\\D/g, \u0027\u0027);\r\n\r\n if (cpf.length != 11) {\r\n return false;\r\n }\r\n\r\n if (Number(cpf) - Number(Array(12).join(cpf[0])) === 0) {\r\n return false;\r\n }\r\n\r\n function verifyDigit(digit) {\r\n var length = 8 \u002B digit;\r\n var sequence = 9 \u002B digit;\r\n var sum = 0;\r\n for (var i = 0; i \u003C length; i\u002B\u002B) {\r\n sum \u002B= Number(cpf.charAt(i)) * (sequence - i);\r\n }\r\n var aux = sum % 11;\r\n if (cpf.charAt(length) != ((aux \u003C 2) ? 0 : 11 - aux)) {\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n return verifyDigit(1) \u0026\u0026 verifyDigit(2);\r\n}\r\n\r\nvalidateCPF(cpf);","IsDeferred":false}]}