{"ScriptPreparationCode":null,"TestCases":[{"Name":"Recursividade","Code":"cnpj = \u002245586424000130\u0022;\r\n\r\nfunction validateCNPJ(cnpj) {\r\n cnpj = cnpj.replace(/\\D/g, \u0027\u0027);\r\n if (cnpj.length != 14) {\r\n return false;\r\n }\r\n if (Number(cnpj) - Number(Array(15).join(cnpj[0])) === 0) {\r\n return false;\r\n }\r\n\r\n function verifyDigit(digit) {\r\n var length = 11 \u002B digit;\r\n var sequence = 4 \u002B digit;\r\n var sum = 0;\r\n for (var i = 0; i \u003C length; i\u002B\u002B) {\r\n sum \u002B= cnpj.charAt(i) * sequence--;\r\n if (sequence \u003C 2) {\r\n sequence = 9;\r\n }\r\n }\r\n var aux = sum % 11;\r\n if (cnpj.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\nvalidateCNPJ(cnpj);","IsDeferred":false},{"Name":"Sem recursividade","Code":"cnpj = \u002212345678901234\u0022;\r\n\r\nfunction validateCNPJ(cnpj) {\r\n cnpj = cnpj.replace(/\\D/g, \u0027\u0027);\r\n if (cnpj.length != 14) {\r\n return false;\r\n }\r\n if (Number(cnpj) - Number(Array(15).join(cnpj[0])) === 0) {\r\n return false;\r\n }\r\n\r\n var length = 12;\r\n var sequence = 5;\r\n var sum = 0;\r\n for (var i = 0; i \u003C length; i\u002B\u002B) {\r\n sum \u002B= cnpj.charAt(i) * sequence--;\r\n if (sequence \u003C 2) {\r\n sequence = 9;\r\n }\r\n }\r\n var aux = sum % 11;\r\n if (cnpj.charAt(length) != (aux \u003C 2 ? 0 : 11 - aux)) {\r\n return false;\r\n }\r\n\r\n length = 13;\r\n sequence = 6;\r\n sum = 0;\r\n for (var i = 0; i \u003C length; i\u002B\u002B) {\r\n sum \u002B= cnpj.charAt(i) * sequence--;\r\n if (sequence \u003C 2) {\r\n sequence = 9;\r\n }\r\n }\r\n aux = sum % 11;\r\n if (cnpj.charAt(length) != (aux \u003C 2 ? 0 : 11 - aux)) {\r\n return false;\r\n }\r\n\r\n return verifyDigit(1) \u0026\u0026 !verifyDigit(2);\r\n}\r\n\r\nconsole.log(validateCNPJ(cnpj));","IsDeferred":false}]}