,

JavaScript Coding Challenges: Test Your Skills with These Questions and Solutions

surendra2surendra Avatar

In this post, we present a series of JavaScript coding challenges that will put your programming skills to the test. Each challenge comes with a detailed explanation and a solution. Whether you’re a beginner looking to learn or an experienced developer looking to sharpen your skills, these challenges have something for everyone.

Q 1 : Given an array of comma-separated strings, determine whether all the alphabets in each pair of strings are matched or not. Write a JavaScript function to achieve this without using loops.?

const input = ['act,cat', 'race,care', 'angular,react', 'actt,caat'];

Expected Output = [true, true, false, false]


// JavaScript function to check if all alphabets are matched in comma-separated strings
function checkAlphabetsMatching(input) {
  const result = input.map((str) => {
    const [str1, str2] = str.split(','); // Split the string into two parts
    const sortedStr1 = str1.split('').sort().join(''); // Sort the characters in the first part
    const sortedStr2 = str2.split('').sort().join(''); // Sort the characters in the second part
    return sortedStr1 === sortedStr2; // Check if the sorted strings match
  });

  return result;
}

const input = ['act,cat', 'race,care', 'angular,react', 'actt,caat'];
const output = checkAlphabetsMatching(input);

console.log(output); // Output: [true, true, false, false]

Tagged in :

surendra2surendra Avatar

You May Love