51
Algorithms and Scripting: Problems and Notes Part 2:
Currently a Monday, time is 6:00 PM I'm feeling pretty tired but I must continue this habit of learning and studying if I wanna be someone for my family and myself.
Basically for ATCGA
return [["A", "T"], ["T","A"], ["C", "G"],["G","C"],["A","T"]]
Problem:
function pair(str) {
}
pairElement("GCG");
function pair(str) {
let letters = str.split("")
function singleLetter(initial) {
if (initial === "G") {
return "C"
} else if (initial === "C") {
return "G"
} else if (initial === "A") {
return "T"
} else if (initial=== "T") {
return "A";
}
}
return letters.map(letter => {
let result = [letter, singleLetter(letter)]
return result;
})
}
console.log(pairElement("ATCGA")); will display [["A", "T"], ["T","A"], ["C", "G"],["G","C"],["A","T"]]
Again this doesn't have to be this complicated, there's other ways to solve this problem. Like, defining an object with all pair possibilities, which allows us to easily find by key or value.
function fearNotLetter(str) {
return str;
}
fearNotLetter("abce");
function fearNotLetter(str) {
let alphabet = "abcdefghijklmnopqrstuvwxyz";
let startAt = alphabet.indexOf(str[0]);
let letters = alphabet.slice(startAt);
for (let i = 0; i < str.length; i++) {
if (letters[i] !== str[i]) { // <-- basically checks if (s !== s), (t !== t), (u !== v) etc.
return letters[i];
}
}
return undefined;
}
console.log(fearNotLetter("stvwx")); will display u
51