checkEquals([1, 2], [1, 3]) → false // Good so far... checkEquals([1, 2], [1, 2]) → false // Yikes! What happened? Rewrite your friend's code so that it correctly checks if two arrays are equal. To be equal, the arrays must have the same elements in the same order. The tests below should pass:
checkEquals([1, 2], [1, 3]) → false // Good so far... checkEquals([1, 2], [1, 2]) → false // Yikes! What happened? Rewrite your friend's code so that it correctly checks if two arrays are equal. To be equal, the arrays must have the same elements in the same order. The tests below should pass:
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
Related questions
Question
question
![To solve this question, your friend writes the following code:
function checkEquals(arr1, arr2) {
if (arr1 === arr2) {
return true
} else {
return false
}
But testing the code, you see that something is not quite right. Running the code yields the
following results:
checkEquals([1, 2], [1, 3]) → false
// Good so far...
checkEquals([1, 2], [1, 2])
// Yikes! What happened?
false
Rewrite your friend's code so that it correctly checks if two arrays are equal. To be equal,
the arrays must have the same elements in the same order. The tests below should pass:](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F26d0d142-3f00-4e75-9a42-94834d4d1c50%2F60b9eb43-1838-4d1e-97f9-3a0f12595071%2F0e8zgy5_processed.png&w=3840&q=75)
Transcribed Image Text:To solve this question, your friend writes the following code:
function checkEquals(arr1, arr2) {
if (arr1 === arr2) {
return true
} else {
return false
}
But testing the code, you see that something is not quite right. Running the code yields the
following results:
checkEquals([1, 2], [1, 3]) → false
// Good so far...
checkEquals([1, 2], [1, 2])
// Yikes! What happened?
false
Rewrite your friend's code so that it correctly checks if two arrays are equal. To be equal,
the arrays must have the same elements in the same order. The tests below should pass:
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning