$(document).ready(function () {
// Замена цифры на b в числе a в позиции i
function changeDigit(a, b, i) {
function st10(n) {
var b = 1;
for (var i = 1; i < n; i++) {
b *= 10;
}
return b;
}
return (((a / st10(i + 2) | 0) * 10) + b) * st10(i + 1) + (a % st10(i + 1));
}
// Подсчёт контрольного числа
// Возврат INT
function calcControlSummSnils(snils) {
// Проверка суммы
function checkSumm(s) {
if (s < 10) {
return "0" + s;
}
if (s < 100) {
return s;
}
if (s === 100 || s === 101) {
return "00";
}
if (s > 101) {
return checkSumm(s % 101);
}
}
// Расчёт суммы
var summ = 0;
for (var i = 0; i < 9; i++) {
summ += (9 - i) * parseInt(snils[i]);
}
console.log(summ);
return checkSumm(summ);
}
// Перевод массива в строку
function arr2str(arr) {
var str = "";
for (var i = 0; i < arr.length; i++) {
str += arr[i];
}
return str;
}
// Убирает из строки лишние символы - возврат массива цифр
function validateSnils(str) {
var digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
var correctStr = [];
for (var i = 0; i < str.length; i++) {
if (str[i] in digits) {
correctStr.push(parseInt(str[i]));
}
}
//console.log(correctStr);
return arr2str(correctStr);
}
// Проверка на совпадание контрольной суммы
function checkSnils(snils) {
if (parseInt(calcControlSummSnils(snils.substring(0, 9))) === parseInt(snils.substring(9, 11))) {
return true;
} else {
return false;
}
}
//
function showAlert(str, type) {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.