Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a JavaScript function compareChars(arr1, arr2) that compares two arrays of chars
- lexicographically (letter by letter). Write JS program charComparer.js that invokes your function
- with the sample input data below and prints the output at the console. */
- "use strict";
- function compareChars(arr1, arr2) {
- if (arr1.length == arr2.length) {
- for (var i = 0; i < arr1.length; i += 1) {
- if (arr1[i] !== arr2[i]) {
- return 'Not Equal';
- }
- }
- return 'Equal';
- } else {
- return 'Not Equal';
- }
- }
- var arr1 = ['1', 'f', '1', 's', 'g', 'j', 'f', 'u', 's', 'q'];
- var arr2 = ['1', 'f', '1', 's', 'g', 'j', 'f', 'u', 's', 'q'];
- console.log(compareChars(arr1, arr2));
- arr1 = ['3', '5', 'g', 'd'];
- arr2 = ['5', '3', 'g', 'd'];
- console.log(compareChars(arr1, arr2));
- arr1 = ['q', 'g', 'q', 'h', 'a', 'k', 'u', '8', '}', 'q', '.', 'h', '|', ';'];
- arr2 = ['6', 'f', 'w', 'q', ':', '”', 'd', '}', ']', 's', 'r'];
- console.log(compareChars(arr1, arr2));
- arr1 = [];
- arr2 = [];
- console.log(compareChars(arr1, arr2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement