Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
|
|
@ -0,0 +1,52 @@
|
|||
function display(numbers) {
|
||||
console.log(`[${numbers.join(", ")}]`);
|
||||
}
|
||||
|
||||
function string_search_single(haystack, needle) {
|
||||
const index = haystack.indexOf(needle);
|
||||
return index;
|
||||
}
|
||||
|
||||
function string_search(haystack, needle) {
|
||||
const result = [];
|
||||
let start = 0;
|
||||
let index = 0;
|
||||
|
||||
while (index >= 0 && start < haystack.length) {
|
||||
const haystackReduced = haystack.substring(start);
|
||||
index = string_search_single(haystackReduced, needle);
|
||||
if (index >= 0) {
|
||||
result.push(start + index);
|
||||
start += index + needle.length;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const texts = [
|
||||
"GCTAGCTCTACGAGTCTA",
|
||||
"GGCTATAATGCGTA",
|
||||
"there would have been a time for such a word",
|
||||
"needle need noodle needle",
|
||||
"DKnuthusesandprogramsanimaginarycomputertheMIXanditsassociatedmachinecodeandassemblylanguages",
|
||||
"Nearby farms grew an acre of alfalfa on the dairy's behalf, with bales of that alfalfa exchanged for milk.",
|
||||
];
|
||||
|
||||
const patterns = ["TCTA", "TAATAAA", "word", "needle", "and", "alfalfa"];
|
||||
|
||||
for (let i = 0; i < texts.length; ++i) {
|
||||
console.log(`text${i + 1} = ${texts[i]}`);
|
||||
}
|
||||
console.log();
|
||||
|
||||
for (let i = 0; i < texts.length; ++i) {
|
||||
const indexes = string_search(texts[i], patterns[i]);
|
||||
console.log(
|
||||
`Found "${patterns[i]}" in 'text${i + 1}' at indexes `
|
||||
);
|
||||
display(string_search(texts[i], patterns[i]));
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Loading…
Add table
Add a link
Reference in a new issue