Created
October 14, 2022 22:11
-
-
Save lukacat10/8927a2a317206886031381ed92d2b0b7 to your computer and use it in GitHub Desktop.
A set of scripts for generating good or bad israeli phone numbers and ids (JS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sum(arr) { | |
return arr.reduce((partialSum, a) => partialSum + a, 0); | |
} | |
Array.prototype.repeat = function(n){ | |
var a = []; | |
for (var i=0;i<n;[i++].push.apply(a,this)); | |
return a; | |
} | |
const ONE_TWO = [1,2, 1,2, 1,2, 1,2, 1] | |
function validate_id(checkid) { | |
let checkidstr = "0".repeat(9 - checkid.length) + checkid | |
let multiplied = [0].repeat(9); | |
for(let i = 0; i < 9; i++) { | |
multiplied[i] = parseInt(checkidstr[i]) * ONE_TWO[i]; | |
if(multiplied[i] > 9) { | |
let asstr = multiplied[i] + ""; | |
let sum_asstr = 0; | |
for(let num of asstr) { | |
sum_asstr += parseInt(num); | |
} | |
multiplied[i] = sum_asstr; | |
} | |
} | |
let summed_multiplied = sum(multiplied); | |
if (summed_multiplied % 10 === 0) { | |
return true; | |
} | |
return false; | |
} | |
function generate_id() { | |
let id = Math.floor(Math.random() * 1000000000); | |
while(!validate_id(id)) { | |
id = Math.floor(Math.random() * 1000000000); | |
} | |
return id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment