scrimba
Prompt Engineering
AI Assisted Coding
Practice: Test a function and generate edge cases
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Practice: Test a function and generate edge cases
AboutCommentsNotes
Practice: Test a function and generate edge cases
Expand for more info
chunkArray.js
run
preview
console
/* 
Practice: Test Your Function and Generate Edge Cases
https://chat.openai.com/

1. Take a minute to read and understand the chunkArray function
2. Ask ChatGPT to generate 3 console.log statements to test the function.
3. Prompt ChatGPt for 5 edge cases
4. Read the edge cases and pick a couple you want your function to
account for (hint: some may involve infinite loops, so don't just run the test cases!)
5. Ask ChatGPT to revise your function based on those edge cases. Be sure
to include instructions (or ask for suggestions) for how you want to deal with them!
*/

/* Prompt: Given an array and a chunk size,
divide the array into many subarrays where each subarray has the specified size. */
function chunkArray(array, size) {
let chunks = [];
for (let i = 0; i < array.length; i += size) {
chunks.push(array.slice(i, i + size));
}
return chunks;
}

console.log(chunkArray([1,2,3,4], 2)); // [[1,2], [3,4]]



Console
[
[
1
,
2
]
,
[
3
,
4
]
]
,
/index.html
-4:55