Use Copilot to Write and Translate a Binary Search Algorithm

Developer Advocate @ GitHub
Search for a command to run...

Developer Advocate @ GitHub
No comments yet. Be the first to comment.
In this series, I will document technical tutorials for navigating GitHub's awesome features!
Practical Use Cases for the AI Pair Programmer
Raise your hand if you've been personally victimized by the question: 'Will AI replace software engineers?' It's a common debate that drives developers to extremes—either avoiding AI entirely or frantically signing up for every AI course available. ...
I recently went down several rabbit holes about building WYSIWYG editors and popovers. While on maternity leave, I finally have time to deeply explore random technical problems without deadlines - a rare opportunity. Thus far, I've focused on contrib...
This blog post uses storytelling to introduce beginners to Verifiable Credentials, followed by a tutorial on creating them in JavaScript and Kotlin. In Our Last Issue... In our previous issue, we met Dawson Webhart, a junior frontend software enginee...

"Our current credit system says, 'Saddle yourself, so we can give you more to saddle.'" Eric Lapin, President of FormFree, stated during a recent TBD live stream. His comment sheds light on a fundamental paradox of the U.S. credit system: it often re...

Technology adoption doesn't happen with one software engineer coding in solitude. Even though big companies like Meta and Microsoft boast of their humble beginnings in a dorm room or a garage, product adoption requires good marketing. Many software e...

Black Girl Bytes
58 posts
I'm a Developer Advocate at GitHub. I'm passionate about community, code, and education! Reach out to me on Twitter ❤️
I learn best from reading, watching, and doing, which means I need various resources to create a robust mental model. When I've studied for interviews, colleges exams, and coding bootcamp, I'll watch videos, complete LeetCode exercises, and write an explanation of the code. Copilot Labs serves as an additional resource giving me more context on why and how specific algorithms work.
I will use Copilot and Copilot Labs to write and understand a binary search algorithm in this blog post.
Ensure that you've installed the GitHub Copilot extension AND the GitHub Copilot Labs extension. Please note: GitHub Copilot is in technical preview, and thus not all users will be able to access this feature. Please join the waitlist if you'd like to sign up for the technical preview.

Step 1: Open your IDE. For this example, I'm using Visual Studio Code via Codespaces. Type a comment that says, "Write a binary search algorithm."

Step 2: Type the keyword "const" on a new line. This should trigger Copilot to provide suggested code to write a binary search algorithm. To accept the suggested code, press the TAB key.



Step 3: Now, we can better understand what the code is accomplishing by converting the code into plain language. Let's open the Copilot Labs sidebar.

Step 4: Highlight the code snippet, and on the top left-hand corner, choose "Explain." Press the "Ask Copilot" button to generate a step-by-step explanation of what's happening in the code snippet.


Step 5: We can also convert this code snippet into Python (or any programming language of your choice). Navigate to the Language Translation of the Copilot Labs sidebar and choose the target language. Press the "Ask Copilot" button to view a version of the code snippet in a different language.


Follow GitHub and me on DEV for more updates on GitHub's newest features!
If you have any feedback you want to share with the team at GitHub, use the Discussion board.