Simple Replacement algorithm
by aninaslyan
JavaScript
function chipher(str, word) {
let alphabet = "abcdefghijklmnopqrstuvwxyz".split("");
let newAlphabet = [...alphabet];
let coded = "", index="", newIndex="", final = [];
let unique = [...new Set(str)];
alphabet.forEach((value) => {
unique.forEach(val => {
if(value.includes(val)){
index = alphabet.indexOf(value);
alphabet.splice(index, 1);
}
});
});
coded = unique.concat(alphabet);
console.log(coded);
word = word.split("");
console.log(word);
word.forEach(v => {
newIndex = newAlphabet.findIndex(k => k==v);
final.push(coded[newIndex]);
});
return final
}
console.log(chipher("alba", "meet"));
//text = prompt("Input text");