feat(curriculum): convert DNA pairing challenge to lab (#62132)

Co-authored-by: Ilenia <26656284+ilenia-magoni@users.noreply.github.com>
This commit is contained in:
Zaira
2025-09-22 13:30:25 +05:00
committed by GitHub
parent 2098a0d364
commit 8f4fdeda58
5 changed files with 131 additions and 0 deletions

View File

@@ -3473,6 +3473,12 @@
"In this lab, you will design a sum all numbers algorithm. This algorithm takes an array of two numbers and returns the sum of those two numbers plus the sum of all the numbers between them."
]
},
"lab-dna-pair-generator": {
"title": "Implement a DNA Pair Generator",
"intro": [
"In this lab you will implement a DNA base pairing algorithm that converts a single DNA strand into complementary base pairs."
]
},
"lab-html-entitiy-converter": {
"title": "Implement an HTML Entity Converter",
"intro": [

View File

@@ -0,0 +1,9 @@
---
title: Introduction to the Implement a DNA Pair Generator
block: lab-dna-pair-generator
superBlock: full-stack-developer
---
## Introduction to the Implement a DNA Pair Generator
In this lab you will implement a DNA base pairing algorithm that converts a single DNA strand into complementary base pairs.

View File

@@ -0,0 +1,100 @@
---
id: afd15382cdfb22c9efe8b7de
title: Implement a DNA Pair Generator
challengeType: 26
dashedName: implement-a-dna-pair-generator
---
# --description--
Pairs of DNA strands consist of nucleobase pairs. Base pairs are represented by the characters <em>AT</em> and <em>CG</em>, which form building blocks of the DNA double helix.
In this lab, you will write a function to match the missing base pairs for the provided DNA strand. For each character in the provided string, find the base pair character.
For example, for the input `GCG`, return `[["G", "C"], ["C", "G"], ["G", "C"]]`
The character and its pair are paired up in an array, and all the arrays are grouped into one encapsulating array.
**Objective**: Fulfill the user stories below and get all the tests to pass to complete the lab.
**User Stories:**
1. You should have a `pairElement` function that takes a string as an argument.
1. The `pairElement` function should return a 2d array.
1. When given `A`, the function should pair it with `T`.
1. When given `T`, the function should pair it with `A`.
1. When given `C`, the function should pair it with `G`.
1. When given `G`, the function should pair it with `C`.
1. Each pair should be returned as an array with the original character first and its complement second.
# --hints--
You should create a function named `pairElement`.
```js
assert.isFunction(pairElement);
```
`pairElement` should take a single argument.
```js
assert.lengthOf(pairElement, 1);
```
`pairElement("ATCGA")` should return `[["A","T"],["T","A"],["C","G"],["G","C"],["A","T"]]`.
```js
assert.deepEqual(pairElement('ATCGA'), [
['A', 'T'],
['T', 'A'],
['C', 'G'],
['G', 'C'],
['A', 'T']
]);
```
`pairElement("TTGAG")` should return `[["T","A"],["T","A"],["G","C"],["A","T"],["G","C"]]`.
```js
assert.deepEqual(pairElement('TTGAG'), [
['T', 'A'],
['T', 'A'],
['G', 'C'],
['A', 'T'],
['G', 'C']
]);
```
`pairElement("CTCTA")` should return `[["C","G"],["T","A"],["C","G"],["T","A"],["A","T"]]`.
```js
assert.deepEqual(pairElement('CTCTA'), [
['C', 'G'],
['T', 'A'],
['C', 'G'],
['T', 'A'],
['A', 'T']
]);
```
# --seed--
## --seed-contents--
```js
```
# --solutions--
```js
var lookup = Object.create(null);
lookup.A = 'T';
lookup.T = 'A';
lookup.C = 'G';
lookup.G = 'C';
function pairElement(str) {
return str.split('').map(function(p) {return [p, lookup[p]];});
}
```

View File

@@ -0,0 +1,15 @@
{
"name": "Implement a DNA Pair Generator",
"isUpcomingChange": false,
"dashedName": "lab-dna-pair-generator",
"helpCategory": "JavaScript",
"blockLayout": "link",
"blockType": "lab",
"challengeOrder": [
{
"id": "afd15382cdfb22c9efe8b7de",
"title": "Implement a DNA Pair Generator"
}
],
"usesMultifileEditor": true
}

View File

@@ -388,6 +388,7 @@
"lecture-working-with-the-arguments-object-and-rest-parameters",
"lab-password-generator",
"lab-sum-all-numbers-algorithm",
"lab-dna-pair-generator",
"lab-html-entitiy-converter",
"lab-optional-arguments-sum-function",
"review-javascript-fundamentals",