DNA Parsing Algorithm [Beginner JavaScript] - Blade Runner 2049

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ม.ค. 2025

ความคิดเห็น • 2

  • @narutofan2120
    @narutofan2120 3 ปีที่แล้ว +3

    Great video and excellent breakdown of your approach to solving the problem.You're an excellent teacher and I really enjoy your content. Bless up

  • @kevinmarques9334
    @kevinmarques9334 6 หลายเดือนก่อน

    Great video, I was practicing on my browser's console. That's my personal solution using some of the builtin array functions from Javascript:
    (() => {
    "use strict";
    const personsArrayInput = [
    "TAGC GTCA GACT TCAG ATCG CGTA TGAC ACTG",
    "GCTA ACTG TGCA CGAT TCGT AGTC TGAC CTAG",
    "GTCA ACTG TGAC TCGT AGCT AGTC GCTA CGAT",
    "CTAG TGAC GCTA TAGC ATCG TCGT AGTC ACTG",
    "ACTG GCTA ACGT TCGA TGAC CTAG TCGT AGCT",
    "GATC AGCT TGCA CTAG TCGT AGCA GTAC CGAT",
    "CGAT TGAC AGCT GACT TCGA TAGC TCGT AGTC",
    "ACTG GCTA ACGT TCGA TGAC CTAG TCGT AGCT", // Duplicate sequence (1)
    "ACTG GCTA ACGT TCGA TGAC CTAG TCGT AGCT", // Duplicate sequence (1.5)
    "TCGA TGAC CTAG GACT AGTC TGCA GCTA ACTG",
    "AGCT TGAC CGTA TCGT ATCG TGCA GACT CTAG",
    "GACT TCGG ATCG AGTC TGCA CGAT AGTC CGTA",
    "GATC AGCT TGCA CTAG TCGT AGCA GTAC CGAT", // Duplicate sequence (2)
    ];
    function findMatchingPair(personsArray) {
    const cache = {};
    personsArray.forEach((dna, key) => {
    if (dna in cache)
    return cache[dna].push(key);
    cache[dna] = [key];
    });
    return Object.values(cache)
    .filter((matches) => matches.length > 1);
    }
    const result = findMatchingPair(personsArrayInput);
    console.log(result);
    })();