Added functions to js
This commit is contained in:
parent
106512b5ad
commit
533b4bb643
1 changed files with 59 additions and 0 deletions
59
banana.js
59
banana.js
|
@ -5,6 +5,13 @@ console.log(bananaencode(1000, 8));
|
|||
console.log(bananarandom());
|
||||
console.log(bananarandom(10));
|
||||
|
||||
console.log(bananadecode("babaduga"));
|
||||
|
||||
console.log(bananacheck("babaduga"));
|
||||
console.log(bananacheck("antani"));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function bananaencode(num, minlength = 1) {
|
||||
|
@ -31,6 +38,58 @@ function bananaencode(num, minlength = 1) {
|
|||
return st;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function bananadecode(word) {
|
||||
alphabets = Array("bcdfglmnprstvz".split(""), "aeiou".split(""));
|
||||
shiftalpha = 0;
|
||||
alphaend = 0;
|
||||
|
||||
numalpha = alphabets.length;
|
||||
|
||||
if ((word.length - alphaend) % numalpha != 0) {
|
||||
return "Invalid banana";
|
||||
}
|
||||
v = 0;
|
||||
|
||||
for (i = 0; i < word.length; i++) {
|
||||
r = (numalpha + i + shiftalpha) % numalpha;
|
||||
if (alphabets[r].indexOf(word[i]) != -1) {
|
||||
v = v * alphabets[r].length + alphabets[r].indexOf(word[i]);
|
||||
} else {
|
||||
return("Invalid character in position " + (i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function bananacheck(word) {
|
||||
alphabets = Array("bcdfglmnprstvz".split(""), "aeiou".split(""));
|
||||
shiftalpha = 0;
|
||||
alphaend = 0;
|
||||
|
||||
numalpha = alphabets.length;
|
||||
|
||||
if ((word.length - alphaend) % numalpha != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 0; i < word.length; i++) {
|
||||
r = (numalpha + i + shiftalpha) % numalpha;
|
||||
if (alphabets[r].indexOf(word[i]) == -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function bananarandom(minlength = 6) {
|
||||
alphabets = Array("bcdfglmnprstvz".split(""), "aeiou".split(""));
|
||||
shiftalpha = 0;
|
||||
|
|
Loading…
Reference in a new issue