chosen
listlengths
2
2
rejected
listlengths
2
2
score_chosen
int64
6
9
score_rejected
int64
1
9
[ { "content": "Write a JavaScript program to find the most commonly occurring item in a given object, considering that the object may contain nested objects. Additionally, handle the case where there are multiple items with the same highest frequency by returning an array of those items. You must solve this prob...
[ { "content": "Write a JavaScript program to find the most commonly occurring item in a given object, considering that the object may contain nested objects. Additionally, handle the case where there are multiple items with the same highest frequency by returning an array of those items. You must solve this prob...
7
3
[ { "content": "Write a JavaScript program to generate a random password of length 10 that includes at least one uppercase letter, one lowercase letter, one digit, one special character, and must not contain any repeating characters. The password must also satisfy the additional constraint of having the uppercase...
[ { "content": "Write a JavaScript program to generate a random password of length 10 that includes at least one uppercase letter, one lowercase letter, one digit, one special character, and must not contain any repeating characters. The password must also satisfy the additional constraint of having the uppercase...
8
4
[ { "content": "Write a JavaScript code to add all the prime numbers between 1 and 1000 and display the total sum.", "role": "user" }, { "content": "Here is the JavaScript code to add all the prime numbers between 1 and 1000 and display the total sum:\n\n```javascript\nfunction isPrime(number) {\n if...
[ { "content": "Write a JavaScript code to add all the prime numbers between 1 and 1000 and display the total sum.", "role": "user" }, { "content": "Here is the JavaScript code to add all the prime numbers between 1 and 1000 and display the total sum:\n\n```javascript\nfunction isPrime(number) {\n if...
9
9
[ { "content": "Create a JavaScript function to compare 2 strings to determine if they are anagrams (words with the same letters as each other). The function should have a time complexity of O(n^2), where n is the length of the longer string. Additionally, the function should not use any built-in JavaScript metho...
[ { "content": "Create a JavaScript function to compare 2 strings to determine if they are anagrams (words with the same letters as each other). The function should have a time complexity of O(n^2), where n is the length of the longer string. Additionally, the function should not use any built-in JavaScript metho...
6
6
[ { "content": "How would you transform a deeply nested JSON object into a valid XML document with JavaScript, ensuring that all nested objects and arrays are correctly converted into their corresponding XML elements and attributes? Additionally, the XML document should have indentation and line breaks for improv...
[ { "content": "How would you transform a deeply nested JSON object into a valid XML document with JavaScript, ensuring that all nested objects and arrays are correctly converted into their corresponding XML elements and attributes? Additionally, the XML document should have indentation and line breaks for improv...
8
8
[ { "content": "Add a function called \"findIndex\" to the following JavaScript code to search for the first occurrence of a specific value in a given array and return its index. The function should also take an optional parameter called \"startIndex\" which represents the index to start the search from. If the v...
[ { "content": "Add a function called \"findIndex\" to the following JavaScript code to search for the first occurrence of a specific value in a given array and return its index. The function should also take an optional parameter called \"startIndex\" which represents the index to start the search from. If the v...
9
2
[ { "content": "Write a JavaScript program to loop through an unsorted array and remove any duplicate elements. Return the modified array.\n\nThe time complexity of your solution should be O(n^2), where n is the length of the input array.\n\nAdditionally, you are not allowed to use any built-in array methods such...
[ { "content": "Write a JavaScript program to loop through an unsorted array and remove any duplicate elements. Return the modified array.\n\nThe time complexity of your solution should be O(n^2), where n is the length of the input array.\n\nAdditionally, you are not allowed to use any built-in array methods such...
8
8
[ { "content": "Create a JavaScript program that prompts the user to input values for each key of an object, with the following additional requirements:\n\n1. Validate the user input to ensure that each key has a valid value. For example, if the user enters an empty string or a number for the \"name\" key, displa...
[ { "content": "Create a JavaScript program that prompts the user to input values for each key of an object, with the following additional requirements:\n\n1. Validate the user input to ensure that each key has a valid value. For example, if the user enters an empty string or a number for the \"name\" key, displa...
9
2
[ { "content": "Using the given array of numbers, write a JavaScript code to calculate the sum of all the numbers using a recursive function. The function should only use a maximum of 10 lines of code. Additionally, you are not allowed to use any built-in JavaScript array methods such as reduce() or map().\n\nnum...
[ { "content": "Using the given array of numbers, write a JavaScript code to calculate the sum of all the numbers using a recursive function. The function should only use a maximum of 10 lines of code. Additionally, you are not allowed to use any built-in JavaScript array methods such as reduce() or map().\n\nnum...
6
6
[ { "content": "Write a JavaScript function that takes in a JSON object and a key as parameters and returns the corresponding value. If the key does not exist in the object, the function should return null. The time complexity of the function should be O(log n), where n is the number of keys in the object.\n\nAdd...
[ { "content": "Write a JavaScript function that takes in a JSON object and a key as parameters and returns the corresponding value. If the key does not exist in the object, the function should return null. The time complexity of the function should be O(log n), where n is the number of keys in the object.\n\nAdd...
7
4
[ { "content": "In JavaScript, write a function which can split a string into its constituent words. The function should handle cases where the string contains punctuation marks, numbers, or special characters. Additionally, the function should handle cases where the string contains multiple consecutive spaces or...
[ { "content": "In JavaScript, write a function which can split a string into its constituent words. The function should handle cases where the string contains punctuation marks, numbers, or special characters. Additionally, the function should handle cases where the string contains multiple consecutive spaces or...
8
1
[ { "content": "Create a node module for connecting to a MongoDB database that includes a connection pooling mechanism and supports SSL/TLS encryption for secure data transmission. Additionally, implement a feature that allows the module to automatically reconnect to the database in case of connection failure, an...
[ { "content": "Create a node module for connecting to a MongoDB database that includes a connection pooling mechanism and supports SSL/TLS encryption for secure data transmission. Additionally, implement a feature that allows the module to automatically reconnect to the database in case of connection failure, an...
7
7
[ { "content": "You need to group an array of objects according to their property and sort the groups in descending order based on the number of items in each group. Output an object containing the grouped items.\n\nRequirements:\n- Time complexity should be O(n*log(n)), where n is the length of the input array.\...
[ { "content": "You need to group an array of objects according to their property and sort the groups in descending order based on the number of items in each group. Output an object containing the grouped items.\n\nRequirements:\n- Time complexity should be O(n*log(n)), where n is the length of the input array.\...
9
4
[ { "content": "Create an algorithm in JavaScript to merge two sorted arrays into one, but without using any additional arrays or data structures. The merged array should be sorted in ascending order.\n\narr1 = [1, 3, 5, 7, 9, 11]\narr2 = [2, 4, 6, 8, 10, 12]\n\nThe original arrays should remain unchanged.\n\nAdd...
[ { "content": "Create an algorithm in JavaScript to merge two sorted arrays into one, but without using any additional arrays or data structures. The merged array should be sorted in ascending order.\n\narr1 = [1, 3, 5, 7, 9, 11]\narr2 = [2, 4, 6, 8, 10, 12]\n\nThe original arrays should remain unchanged.\n\nAdd...
7
2
[ { "content": "Create a JavaScript function that takes an array of objects and returns an array of objects with unique values by a specified key. The function should also exclude any objects where the value of a secondary key is less than a specified threshold. Additionally, the function should handle cases wher...
[ { "content": "Create a JavaScript function that takes an array of objects and returns an array of objects with unique values by a specified key. The function should also exclude any objects where the value of a secondary key is less than a specified threshold. Additionally, the function should handle cases wher...
7
3
[ { "content": "Please write a JavaScript function that takes two parameters: a webpage content and a text to be searched. The function should return the number of times the specific text appears in the webpage content. The function should be case-sensitive.\n\nNote: The webpage content can be any valid string of...
[ { "content": "Please write a JavaScript function that takes two parameters: a webpage content and a text to be searched. The function should return the number of times the specific text appears in the webpage content. The function should be case-sensitive.\n\nNote: The webpage content can be any valid string of...
6
6
[ { "content": "Create a JavaScript program to accept user input and calculate the factorial of the number provided. The program should handle negative numbers and fractions by printing out an error message stating that factorial is not defined for negative numbers or fractions.\n\nThe program should also handle ...
[ { "content": "Create a JavaScript program to accept user input and calculate the factorial of the number provided. The program should handle negative numbers and fractions by printing out an error message stating that factorial is not defined for negative numbers or fractions.\n\nThe program should also handle ...
7
3
[ { "content": "Develop a JavaScript function that takes in a CSS selector as a parameter and displays the elements in an ordered list, but only for elements that have a specific attribute \"data-display\" set to true. Additionally, you must implement the following requirements:\n1. The function should ignore ele...
[ { "content": "Develop a JavaScript function that takes in a CSS selector as a parameter and displays the elements in an ordered list, but only for elements that have a specific attribute \"data-display\" set to true. Additionally, you must implement the following requirements:\n1. The function should ignore ele...
9
9
[ { "content": "Write a JavaScript function to filter out all falsy values from an array and return a new array without modifying the original one. The function should also exclude any null values from the array and only include values that are of type string, number, or boolean. Falsy values to be filtered out i...
[ { "content": "Write a JavaScript function to filter out all falsy values from an array and return a new array without modifying the original one. The function should also exclude any null values from the array and only include values that are of type string, number, or boolean. Falsy values to be filtered out i...
9
2
[ { "content": "Write a JavaScript program to convert an array of objects into a comma-separated values (CSV) string with column headers. The program should handle the case where the array is empty and also convert all the values into uppercase. Additionally, the program should only include objects that have a 'n...
[ { "content": "Write a JavaScript program to convert an array of objects into a comma-separated values (CSV) string with column headers. The program should handle the case where the array is empty and also convert all the values into uppercase. Additionally, the program should only include objects that have a 'n...
6
6
[ { "content": "Create a function in JavaScript that takes in an array of strings as a parameter. The function should iterate over the array and return a new array that contains only the strings that are longer than 5 characters. However, the function should now also check if each string contains at least one upp...
[ { "content": "Create a function in JavaScript that takes in an array of strings as a parameter. The function should iterate over the array and return a new array that contains only the strings that are longer than 5 characters. However, the function should now also check if each string contains at least one upp...
8
2
[ { "content": "Please implement a function in JavaScript that finds the maximum value in an array of numbers. The time complexity should be O(n) and the space complexity should be O(1).\n\nThe function should also return the index of the maximum value in addition to the value itself.\n\nAdditionally, ensure that...
[ { "content": "Please implement a function in JavaScript that finds the maximum value in an array of numbers. The time complexity should be O(n) and the space complexity should be O(1).\n\nThe function should also return the index of the maximum value in addition to the value itself.\n\nAdditionally, ensure that...
7
7
[ { "content": "Write a JavaScript program to compare two given strings, and count the number of common alphanumeric characters between them. The comparison should be case-insensitive. The strings can contain any characters from ASCII range 0-127. Your program should handle strings of different lengths and return...
[ { "content": "Write a JavaScript program to compare two given strings, and count the number of common alphanumeric characters between them. The comparison should be case-insensitive. The strings can contain any characters from ASCII range 0-127. Your program should handle strings of different lengths and return...
6
1
[ { "content": "Write a JS function to make an authenticated API request and retrieve data from a specific endpoint of the API. The function should require an API key and a user token to be passed as parameters. The returned data should be filtered based on multiple conditions specified by the user, including a r...
[ { "content": "Write a JS function to make an authenticated API request and retrieve data from a specific endpoint of the API. The function should require an API key and a user token to be passed as parameters. The returned data should be filtered based on multiple conditions specified by the user, including a r...
8
8
[ { "content": "Create a JavaScript function called \"calculateSquareRoots\" that takes in an array of positive integers and returns an array of rounded square roots for each number. The function should have a time complexity of O(n), where n is the length of the input array.\n\nAdditionally, the function should ...
[ { "content": "Create a JavaScript function called \"calculateSquareRoots\" that takes in an array of positive integers and returns an array of rounded square roots for each number. The function should have a time complexity of O(n), where n is the length of the input array.\n\nAdditionally, the function should ...
7
7
[ { "content": "Develop a function in JavaScript to get the maximum and minimum values from an array, along with their corresponding index positions. The function should also handle arrays that contain duplicate values. Additionally, the function should return the count of how many times each unique value appears...
[ { "content": "Develop a function in JavaScript to get the maximum and minimum values from an array, along with their corresponding index positions. The function should also handle arrays that contain duplicate values. Additionally, the function should return the count of how many times each unique value appears...
7
4
[ { "content": "Using a JavaScript array of strings, write code to remove all strings that start with \"a\" and end with \"t\". If the string is empty or contains only spaces, ignore it. Return the modified array.\n\nRequirements:\n1. The time complexity of the solution should be O(n), where n is the length of th...
[ { "content": "Using a JavaScript array of strings, write code to remove all strings that start with \"a\" and end with \"t\". If the string is empty or contains only spaces, ignore it. Return the modified array.\n\nRequirements:\n1. The time complexity of the solution should be O(n), where n is the length of th...
7
7
[ { "content": "Create a JavaScript object that stores the properties name, age, favorite color, and birthdate. Additionally, the object should have a method called \"calculateAgeInMonths\" that calculates and returns the age of the person in months. The age should be calculated based on the current date and the ...
[ { "content": "Create a JavaScript object that stores the properties name, age, favorite color, and birthdate. Additionally, the object should have a method called \"calculateAgeInMonths\" that calculates and returns the age of the person in months. The age should be calculated based on the current date and the ...
8
2
[ { "content": "Write a JavaScript code snippet to remove all children that have a specific attribute called 'data-type' with a value of 'mytype' in a div with id 'myDiv'. Additionally, the code should count the number of children that were removed and log it to the console. The code should also check if the div ...
[ { "content": "Write a JavaScript code snippet to remove all children that have a specific attribute called 'data-type' with a value of 'mytype' in a div with id 'myDiv'. Additionally, the code should count the number of children that were removed and log it to the console. The code should also check if the div ...
9
1
[ { "content": "Using the given JSON data, create a JavaScript object and output the sum of the ages of all people in the \"people\" array. However, you are not allowed to use any looping constructs (e.g. for loop, while loop), higher-order array methods (e.g. map, reduce), or recursion to calculate the sum. You ...
[ { "content": "Using the given JSON data, create a JavaScript object and output the sum of the ages of all people in the \"people\" array. However, you are not allowed to use any looping constructs (e.g. for loop, while loop), higher-order array methods (e.g. map, reduce), or recursion to calculate the sum. You ...
8
4
[ { "content": "Create a function in JavaScript to show a message on the webpage using an alert box. The message should be customizable and the function should take the message as a parameter. Additionally, the function should only display the message if it contains at least 10 characters, does not contain any sp...
[ { "content": "Create a function in JavaScript to show a message on the webpage using an alert box. The message should be customizable and the function should take the message as a parameter. Additionally, the function should only display the message if it contains at least 10 characters, does not contain any sp...
9
3
[ { "content": "Create an algorithm in JavaScript that calculates the weighted average of a series of numbers. Each number in the series is associated with a weight, and the weighted average is calculated by multiplying each number by its corresponding weight, summing them up, and dividing the total by the sum of...
[ { "content": "Create an algorithm in JavaScript that calculates the weighted average of a series of numbers. Each number in the series is associated with a weight, and the weighted average is calculated by multiplying each number by its corresponding weight, summing them up, and dividing the total by the sum of...
8
2
[ { "content": "Using jQuery, select all paragraph elements on a page that have a specific class name \"fade-in\", hide them initially, and then fade them in after a random time interval between 2 and 4 seconds. Additionally, implement error handling to display an alert message if there is a problem with the fade...
[ { "content": "Using jQuery, select all paragraph elements on a page that have a specific class name \"fade-in\", hide them initially, and then fade them in after a random time interval between 2 and 4 seconds. Additionally, implement error handling to display an alert message if there is a problem with the fade...
8
3
[ { "content": "Write a JavaScript function that takes in an array of numbers and checks if there are any duplicate numbers. If there are, return the string \"Duplicate numbers found\", otherwise return the string \"No duplicate numbers found\". The function should have a time complexity of O(n), where n is the l...
[ { "content": "Write a JavaScript function that takes in an array of numbers and checks if there are any duplicate numbers. If there are, return the string \"Duplicate numbers found\", otherwise return the string \"No duplicate numbers found\". The function should have a time complexity of O(n), where n is the l...
6
4
[ { "content": "Write a JavaScript function that returns a random prime number from a given array of prime numbers. However, you are not allowed to use any built-in random number generator functions or libraries. The function should also have a time complexity of O(1) and a space complexity of O(1).\n\nprimeNumbe...
[ { "content": "Write a JavaScript function that returns a random prime number from a given array of prime numbers. However, you are not allowed to use any built-in random number generator functions or libraries. The function should also have a time complexity of O(1) and a space complexity of O(1).\n\nprimeNumbe...
7
7
[ { "content": "Write a JavaScript program to create a class 'Shape' with the following specifications:\n1. The class should have a constructor that takes in two parameters: 'width' and 'height'. Both parameters must be positive numbers.\n2. The class should have a method named 'calculateArea' that calculates and...
[ { "content": "Write a JavaScript program to create a class 'Shape' with the following specifications:\n1. The class should have a constructor that takes in two parameters: 'width' and 'height'. Both parameters must be positive numbers.\n2. The class should have a method named 'calculateArea' that calculates and...
8
2
[ { "content": "Generate a two-dimensional array of random integers in JavaScript, where each integer must be unique within its row and column. Additionally, implement a function to check if the array is a magic square. A magic square is a square grid of numbers, where the sum of each row, column, and diagonal ar...
[ { "content": "Generate a two-dimensional array of random integers in JavaScript, where each integer must be unique within its row and column. Additionally, implement a function to check if the array is a magic square. A magic square is a square grid of numbers, where the sum of each row, column, and diagonal ar...
7
1
[ { "content": "Create a JavaScript program to provide real-time search results for a given list of elements. The list can contain any type of data, including numbers, strings, and objects. \n\nlist = [1, \"Apple\", {name: \"John\", age: 25}, \"Banana\", 5, \"Orange\"]\n\nYour program should allow the user to sea...
[ { "content": "Create a JavaScript program to provide real-time search results for a given list of elements. The list can contain any type of data, including numbers, strings, and objects. \n\nlist = [1, \"Apple\", {name: \"John\", age: 25}, \"Banana\", 5, \"Orange\"]\n\nYour program should allow the user to sea...
6
4
[ { "content": "Create a responsive HTML page with a heading, a paragraph of text, and an image. Additionally, include a button that, when clicked, changes the background color of the page to a random color. Use CSS to style the page, ensuring that the heading is centered, the paragraph has a specific font size, ...
[ { "content": "Create a responsive HTML page with a heading, a paragraph of text, and an image. Additionally, include a button that, when clicked, changes the background color of the page to a random color. Use CSS to style the page, ensuring that the heading is centered, the paragraph has a specific font size, ...
8
8
[ { "content": "Write a JavaScript program to accept an array of strings and return a new array containing only the strings that are palindromes. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward.\n\nYour program should ignore any non-alphanumeric cha...
[ { "content": "Write a JavaScript program to accept an array of strings and return a new array containing only the strings that are palindromes. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward.\n\nYour program should ignore any non-alphanumeric cha...
9
4
[ { "content": "Update this JavaScript code to use modern coding practices. \n1. Implement a function named \"checkValue\" that takes an argument \"value\".\n2. Inside the function, use the strict equality operator (===) instead of the loose equality operator (==) to compare \"value\" with 10.\n3. If \"value\" is...
[ { "content": "Update this JavaScript code to use modern coding practices. \n1. Implement a function named \"checkValue\" that takes an argument \"value\".\n2. Inside the function, use the strict equality operator (===) instead of the loose equality operator (==) to compare \"value\" with 10.\n3. If \"value\" is...
7
1
[ { "content": "Demonstrate how to use the following JavaScript function Math.max(arg1, arg2, ...args) to find the maximum value among an array of numbers.\n\nWrite a function called findMaxValue that takes in an array of numbers as input and returns the maximum value from the array.\n\nExample:\nfindMaxValue([1,...
[ { "content": "Demonstrate how to use the following JavaScript function Math.max(arg1, arg2, ...args) to find the maximum value among an array of numbers.\n\nWrite a function called findMaxValue that takes in an array of numbers as input and returns the maximum value from the array.\n\nExample:\nfindMaxValue([1,...
6
6
[ { "content": "Create a function in JavaScript that takes an array of temperatures and returns the mode temperature.\n\nNote: The array may contain duplicate values.\n\n#Difficulties Added#\n- Changing the desired output from median to mode, which requires finding the most frequently occurring temperature in the...
[ { "content": "Create a function in JavaScript that takes an array of temperatures and returns the mode temperature.\n\nNote: The array may contain duplicate values.\n\n#Difficulties Added#\n- Changing the desired output from median to mode, which requires finding the most frequently occurring temperature in the...
6
6
[ { "content": "Write a JavaScript function that takes in a string as a parameter and returns an object containing the number of times each word appears in the string. The function should be case insensitive and ignore punctuation marks. Additionally, the function should exclude common stop words such as \"the\",...
[ { "content": "Write a JavaScript function that takes in a string as a parameter and returns an object containing the number of times each word appears in the string. The function should be case insensitive and ignore punctuation marks. Additionally, the function should exclude common stop words such as \"the\",...
9
4
[ { "content": "What are the characteristics and features of a higher-order function in JavaScript? Provide examples of erroneous code that might result in unexpected behavior, specifically focusing on the concept of function composition and closures.\n\nDifficulty Increase:\n1. Expect the candidate to explain th...
[ { "content": "What are the characteristics and features of a higher-order function in JavaScript? Provide examples of erroneous code that might result in unexpected behavior, specifically focusing on the concept of function composition and closures.\n\nDifficulty Increase:\n1. Expect the candidate to explain th...
9
2
[ { "content": "Write a Node.js command to rotate an array by a given number of positions in place without using any built-in array methods or extra space. The command should handle arrays of any size, including empty arrays. The rotated array should maintain the original order of the elements. The number of posi...
[ { "content": "Write a Node.js command to rotate an array by a given number of positions in place without using any built-in array methods or extra space. The command should handle arrays of any size, including empty arrays. The rotated array should maintain the original order of the elements. The number of posi...
9
2
[ { "content": "Create a function in JavaScript to replace all occurrences of the word \"hello\" in a given string with the word \"goodbye\", while also replacing any spaces in the string with underscores, converting all letters to uppercase, and ensuring that the resulting string has at least 10 characters and c...
[ { "content": "Create a function in JavaScript to replace all occurrences of the word \"hello\" in a given string with the word \"goodbye\", while also replacing any spaces in the string with underscores, converting all letters to uppercase, and ensuring that the resulting string has at least 10 characters and c...
8
4
[ { "content": "Write a function in JavaScript to extract the Kth highest digit from a given number. The number can be a positive or negative integer. The number will not exceed 10^15 in absolute value and K will be between 1 and the number of digits in the number.\n\nExample:\nInput: \nnumber = -98256473\nK = 3\...
[ { "content": "Write a function in JavaScript to extract the Kth highest digit from a given number. The number can be a positive or negative integer. The number will not exceed 10^15 in absolute value and K will be between 1 and the number of digits in the number.\n\nExample:\nInput: \nnumber = -98256473\nK = 3\...
8
8
[ { "content": "Generate a 20 digit random number that contains at least two distinct prime numbers using a JavaScript function.", "role": "user" }, { "content": "You can use the following JavaScript function to generate a 20-digit random number that contains at least two distinct prime numbers:\n\n``...
[ { "content": "Generate a 20 digit random number that contains at least two distinct prime numbers using a JavaScript function.", "role": "user" }, { "content": "You can use the following JavaScript function to generate a 20-digit random number that contains at least two distinct prime numbers:\n\n``...
7
7
[ { "content": "Correct the following JavaScript code to print the first letter of the given string. Ensure that the solution uses a recursive function to find the first letter. The code should have a time complexity of O(n), where n is the length of the string. Additionally, the solution should not use any built...
[ { "content": "Correct the following JavaScript code to print the first letter of the given string. Ensure that the solution uses a recursive function to find the first letter. The code should have a time complexity of O(n), where n is the length of the string. Additionally, the solution should not use any built...
8
4
[ { "content": "Compute the minimum of 10,000 given numbers using a JavaScript function. The function should have a time complexity of O(n) and a space complexity of O(1).\n\nIn addition, the numbers given to the function may include both positive and negative numbers.\n\nHowever, you are now required to implemen...
[ { "content": "Compute the minimum of 10,000 given numbers using a JavaScript function. The function should have a time complexity of O(n) and a space complexity of O(1).\n\nIn addition, the numbers given to the function may include both positive and negative numbers.\n\nHowever, you are now required to implemen...
9
1
[ { "content": "Write a function in JavaScript to delete duplicate characters from a string while maintaining the original order of the characters. The function should also handle strings containing both uppercase and lowercase letters. The resulting string should be sorted in ascending order based on the ASCII v...
[ { "content": "Write a function in JavaScript to delete duplicate characters from a string while maintaining the original order of the characters. The function should also handle strings containing both uppercase and lowercase letters. The resulting string should be sorted in ascending order based on the ASCII v...
7
7
[ { "content": "Change the following JavaScript code so that it calculates and prints out the cube root of a given number using a recursive algorithm. Additionally, modify the code to use tail recursion instead of a loop.\n\nfunction cubeRoot(n) {\n if (n === 0 || n === 1) {\n return n;\n }\n\n function fin...
[ { "content": "Change the following JavaScript code so that it calculates and prints out the cube root of a given number using a recursive algorithm. Additionally, modify the code to use tail recursion instead of a loop.\n\nfunction cubeRoot(n) {\n if (n === 0 || n === 1) {\n return n;\n }\n\n function fin...
6
6
[ { "content": "Replace the following placeholders with appropriate variables in the given JavaScript code. The variables should be dynamically generated based on the user's input.\n\nconst user_name = __PLACEHOLDER__;\nconst secret_code = __PLACEHOLDER__;\n\nconsole.log('Hello, ' + user_name + '!');\nconsole.log...
[ { "content": "Replace the following placeholders with appropriate variables in the given JavaScript code. The variables should be dynamically generated based on the user's input.\n\nconst user_name = __PLACEHOLDER__;\nconst secret_code = __PLACEHOLDER__;\n\nconsole.log('Hello, ' + user_name + '!');\nconsole.log...
9
1
[ { "content": "Given a Javascript string, write a function to extract all data enclosed within specific delimiters. The function should only extract data that matches a given grammar rule, which is to have at least one uppercase letter. Provide a code example with erroneous syntax that attempts to extract the da...
[ { "content": "Given a Javascript string, write a function to extract all data enclosed within specific delimiters. The function should only extract data that matches a given grammar rule, which is to have at least one uppercase letter. Provide a code example with erroneous syntax that attempts to extract the da...
7
3
[ { "content": "Write a JavaScript code to find the sum of all elements in an array. The array can contain both positive and negative integers. Additionally, the array can also contain floating-point numbers. If the array contains any non-numeric values, they should be ignored.\n\nThe time complexity of the solut...
[ { "content": "Write a JavaScript code to find the sum of all elements in an array. The array can contain both positive and negative integers. Additionally, the array can also contain floating-point numbers. If the array contains any non-numeric values, they should be ignored.\n\nThe time complexity of the solut...
6
6
[ { "content": "Write a function in JavaScript which takes an array of numbers and returns the average of all the numbers. The function should not use any built-in array or math functions, and should not use any loops, recursion, or the reduce method. The function should also handle cases where the input array is...
[ { "content": "Write a function in JavaScript which takes an array of numbers and returns the average of all the numbers. The function should not use any built-in array or math functions, and should not use any loops, recursion, or the reduce method. The function should also handle cases where the input array is...
6
3
[ { "content": "Create a method in JavaScript to convert a string to camel case, but without using any built-in string manipulation methods or regular expressions, and without using any loops or recursion. Additionally, you are not allowed to use any temporary variables or arrays.", "role": "user" }, { ...
[ { "content": "Create a method in JavaScript to convert a string to camel case, but without using any built-in string manipulation methods or regular expressions, and without using any loops or recursion. Additionally, you are not allowed to use any temporary variables or arrays.", "role": "user" }, { ...
6
3
[ { "content": "Explain the purpose of the ``await`` operator in an asynchronous JavaScript function, and provide an example demonstrating its usage with Promise chaining, error handling, and multiple concurrent requests. Additionally, optimize the example to handle a large number of concurrent requests efficient...
[ { "content": "Explain the purpose of the ``await`` operator in an asynchronous JavaScript function, and provide an example demonstrating its usage with Promise chaining, error handling, and multiple concurrent requests. Additionally, optimize the example to handle a large number of concurrent requests efficient...
7
3
[ { "content": "Write a JavaScript program to detect if a given element exists in an array or not. The array may contain duplicate elements. Additionally, the program should handle cases where the search element is not of the same type as the elements in the array. The program should have a time complexity of O(l...
[ { "content": "Write a JavaScript program to detect if a given element exists in an array or not. The array may contain duplicate elements. Additionally, the program should handle cases where the search element is not of the same type as the elements in the array. The program should have a time complexity of O(l...
6
6
[ { "content": "Write a query in MongoDB that selects all documents in a given collection where the value of a specific field is greater than a given number, less than a specific date, and belongs to a specific category. The query should also return the documents sorted by a different field in descending order, a...
[ { "content": "Write a query in MongoDB that selects all documents in a given collection where the value of a specific field is greater than a given number, less than a specific date, and belongs to a specific category. The query should also return the documents sorted by a different field in descending order, a...
6
1
[ { "content": "Write a function in JavaScript to validate a credit card number according to the Luhn algorithm. The function should take the credit card number as a parameter and return true if the card is valid, otherwise return false. \n\nAdditionally, the function should check if the card belongs to a specifi...
[ { "content": "Write a function in JavaScript to validate a credit card number according to the Luhn algorithm. The function should take the credit card number as a parameter and return true if the card is valid, otherwise return false. \n\nAdditionally, the function should check if the card belongs to a specifi...
8
2
[ { "content": "Write a code snippet in Javascript to find the most frequently occurring word in a string, ignoring any punctuation marks and considering case sensitivity. If there are multiple words with the same highest frequency, return the one that comes first alphabetically. In addition, consider the followi...
[ { "content": "Write a code snippet in Javascript to find the most frequently occurring word in a string, ignoring any punctuation marks and considering case sensitivity. If there are multiple words with the same highest frequency, return the one that comes first alphabetically. In addition, consider the followi...
8
8
[ { "content": "Create a program in JavaScript that can detect a palindrome. The program should ignore any punctuation marks, white spaces, and numbers in the string. The program should also be case-insensitive when determining if a word is a palindrome. Additionally, the program should handle multi-word palindro...
[ { "content": "Create a program in JavaScript that can detect a palindrome. The program should ignore any punctuation marks, white spaces, and numbers in the string. The program should also be case-insensitive when determining if a word is a palindrome. Additionally, the program should handle multi-word palindro...
7
3
[ { "content": "Write a function in JavaScript to perform the following operation:\nMultiply two numbers a and b. The function should have a time complexity of O(log n) and should not use the * operator.\n\nNote: You are allowed to use bitwise operations, addition, and subtraction.", "role": "user" }, { ...
[ { "content": "Write a function in JavaScript to perform the following operation:\nMultiply two numbers a and b. The function should have a time complexity of O(log n) and should not use the * operator.\n\nNote: You are allowed to use bitwise operations, addition, and subtraction.", "role": "user" }, { ...
6
3
[ { "content": "Please create a class in JavaScript for managing a playlist of songs. The class should have the following functionalities:\n\n1. Add a song to the playlist. Each song should have a title, artist, album, genre, and duration (in seconds). The playlist should have a maximum capacity of 100 songs.\n2....
[ { "content": "Please create a class in JavaScript for managing a playlist of songs. The class should have the following functionalities:\n\n1. Add a song to the playlist. Each song should have a title, artist, album, genre, and duration (in seconds). The playlist should have a maximum capacity of 100 songs.\n2....
6
3
[ { "content": "Create a JavaScript function that will add two strings together. The strings may contain numbers, special characters, and white spaces. The function should return the result as a string. The function should handle strings with different character encodings and ensure that the resulting string main...
[ { "content": "Create a JavaScript function that will add two strings together. The strings may contain numbers, special characters, and white spaces. The function should return the result as a string. The function should handle strings with different character encodings and ensure that the resulting string main...
7
7
[ { "content": "Write a code snippet to remove all white spaces from a given string in JavaScript, while preserving the spaces between words. The solution should have a time complexity of O(n) and should not use any built-in JavaScript methods or regular expressions. Additionally, the solution should not use any ...
[ { "content": "Write a code snippet to remove all white spaces from a given string in JavaScript, while preserving the spaces between words. The solution should have a time complexity of O(n) and should not use any built-in JavaScript methods or regular expressions. Additionally, the solution should not use any ...
7
7
[ { "content": "Generate a random sphere with a random radius between 50 and 200 in JavaScript, and calculate the surface area of the sphere.", "role": "user" }, { "content": "To generate a random sphere with a random radius between 50 and 200 in JavaScript, you can use the following code:\n\n```javas...
[ { "content": "Generate a random sphere with a random radius between 50 and 200 in JavaScript, and calculate the surface area of the sphere.", "role": "user" }, { "content": "To generate a random sphere with a random radius between 50 and 200 in JavaScript, you can use the following code:\n\n```javas...
8
2
[ { "content": "Generate 10 random strings of 12 characters in length with JavaScript. Each string must contain at least three uppercase letters, three lowercase letters, three numbers, and three special characters. Additionally, each string must have no consecutive characters that are the same (e.g., \"aa\" or \...
[ { "content": "Generate 10 random strings of 12 characters in length with JavaScript. Each string must contain at least three uppercase letters, three lowercase letters, three numbers, and three special characters. Additionally, each string must have no consecutive characters that are the same (e.g., \"aa\" or \...
9
9
[ { "content": "Write a JavaScript function that takes a parameter `className` and returns an array of all elements that have the class `className` and are also direct children of an element with the id `parentID`. The function should also filter out any elements that have a data attribute called `data-ignore` wi...
[ { "content": "Write a JavaScript function that takes a parameter `className` and returns an array of all elements that have the class `className` and are also direct children of an element with the id `parentID`. The function should also filter out any elements that have a data attribute called `data-ignore` wi...
8
2
[ { "content": "Create a JavaScript object representing a student's academic record with the following requirements:\n\n- The object must have the properties: name, age, and grades.\n- The name property must be a string and cannot exceed 50 characters.\n- The age property must be a positive integer between 10 and...
[ { "content": "Create a JavaScript object representing a student's academic record with the following requirements:\n\n- The object must have the properties: name, age, and grades.\n- The name property must be a string and cannot exceed 50 characters.\n- The age property must be a positive integer between 10 and...
9
2
[ { "content": "Create a JavaScript function to get the highest value from a given array. Additionally, ensure that the function does not use any built-in array sorting or comparison methods (e.g. `sort()`, `Math.max()`, etc.) and has a time complexity of O(n). In addition, the function should only iterate throug...
[ { "content": "Create a JavaScript function to get the highest value from a given array. Additionally, ensure that the function does not use any built-in array sorting or comparison methods (e.g. `sort()`, `Math.max()`, etc.) and has a time complexity of O(n). In addition, the function should only iterate throug...
7
7
[ { "content": "Write a JavaScript program that takes an array of strings as an argument and then prints those strings in reverse alphabetical order.\n\nThe time complexity of your solution should be O(n^2), where n is the length of the input array.\n\nDo not use any built-in sorting functions or methods. You nee...
[ { "content": "Write a JavaScript program that takes an array of strings as an argument and then prints those strings in reverse alphabetical order.\n\nThe time complexity of your solution should be O(n^2), where n is the length of the input array.\n\nDo not use any built-in sorting functions or methods. You nee...
9
9
[ { "content": "Create a React component for displaying a list of books. The component should have a search functionality where the user can enter a keyword and the list of books will be filtered based on the keyword. The search functionality should be case-insensitive. Additionally, the component should have a s...
[ { "content": "Create a React component for displaying a list of books. The component should have a search functionality where the user can enter a keyword and the list of books will be filtered based on the keyword. The search functionality should be case-insensitive. Additionally, the component should have a s...
6
2
[ { "content": "Write a function in JavaScript that takes a paragraph as input and returns the number of distinct words in the paragraph. The function should ignore punctuation marks, treat uppercase and lowercase letters as the same word, and also handle contractions. Additionally, the function should now remove...
[ { "content": "Write a function in JavaScript that takes a paragraph as input and returns the number of distinct words in the paragraph. The function should ignore punctuation marks, treat uppercase and lowercase letters as the same word, and also handle contractions. Additionally, the function should now remove...
7
7
[ { "content": "Write a JavaScript function that takes an array of numbers and a function as arguments and returns an array with the same numbers as the input, but sorted in ascending order. The input array can contain duplicate numbers and negative numbers as well. The sorting algorithm used should be more effic...
[ { "content": "Write a JavaScript function that takes an array of numbers and a function as arguments and returns an array with the same numbers as the input, but sorted in ascending order. The input array can contain duplicate numbers and negative numbers as well. The sorting algorithm used should be more effic...
6
6
[ { "content": "Write a JavaScript code to copy an array including its elements. However, the copied array should only contain odd numbers from the original array and should be sorted in ascending order. If the original array does not contain any odd numbers, return an empty array. The code should use recursion t...
[ { "content": "Write a JavaScript code to copy an array including its elements. However, the copied array should only contain odd numbers from the original array and should be sorted in ascending order. If the original array does not contain any odd numbers, return an empty array. The code should use recursion t...
9
9
[ { "content": "Write a JavaScript class that generates a random integer between 1 and 100, and keeps track of the number of times each integer has been generated. The class should have a property called `generatedNumbers` that is initialized as an empty object. This object will store the generated numbers as key...
[ { "content": "Write a JavaScript class that generates a random integer between 1 and 100, and keeps track of the number of times each integer has been generated. The class should have a property called `generatedNumbers` that is initialized as an empty object. This object will store the generated numbers as key...
6
3
[ { "content": "Write a JavaScript program to extract the first word of a given string, excluding any leading or trailing spaces, punctuation marks, or numbers. If the string contains multiple words, the program should only extract the first word. If the string starts with a punctuation mark or number, the progra...
[ { "content": "Write a JavaScript program to extract the first word of a given string, excluding any leading or trailing spaces, punctuation marks, or numbers. If the string contains multiple words, the program should only extract the first word. If the string starts with a punctuation mark or number, the progra...
9
9
[ { "content": "Create a JavaScript program to capitalize each word in a given string while ignoring words that contain numbers. Also, ensure that the program ignores any special characters or symbols within the words. Additionally, handle cases where the input string may contain multiple sentences or paragraphs,...
[ { "content": "Create a JavaScript program to capitalize each word in a given string while ignoring words that contain numbers. Also, ensure that the program ignores any special characters or symbols within the words. Additionally, handle cases where the input string may contain multiple sentences or paragraphs,...
7
7
[ { "content": "Write a JavaScript program to get the number of business days (excluding weekends and public holidays) in a given month and year, taking into account the specific public holidays of a particular country.\n\nYour program should take into account the following additional constraints:\n\n1. The publi...
[ { "content": "Write a JavaScript program to get the number of business days (excluding weekends and public holidays) in a given month and year, taking into account the specific public holidays of a particular country.\n\nYour program should take into account the following additional constraints:\n\n1. The publi...
7
4
[ { "content": "Design a JavaScript function to convert a given time in 24-hour notation to 12-hour notation. Additionally, the function should handle time inputs with both valid and invalid formats, including formats with milliseconds and time zones, and return an appropriate error message if the format is inval...
[ { "content": "Design a JavaScript function to convert a given time in 24-hour notation to 12-hour notation. Additionally, the function should handle time inputs with both valid and invalid formats, including formats with milliseconds and time zones, and return an appropriate error message if the format is inval...
6
4
[ { "content": "Write a JavaScript function that detects whether or not the current browser is Internet Explorer. Additionally, the function should display an error message if the browser is detected as Internet Explorer, stating that the website does not support Internet Explorer and recommending the user to swi...
[ { "content": "Write a JavaScript function that detects whether or not the current browser is Internet Explorer. Additionally, the function should display an error message if the browser is detected as Internet Explorer, stating that the website does not support Internet Explorer and recommending the user to swi...
7
4
[ { "content": "Please write a JavaScript function that calculates the sum of the squares of two numbers, with a time complexity of O(1). The function should handle input validation and only accept numbers as input.\n\nHowever, you are not allowed to use the multiplication operator (*) or the exponentiation opera...
[ { "content": "Please write a JavaScript function that calculates the sum of the squares of two numbers, with a time complexity of O(1). The function should handle input validation and only accept numbers as input.\n\nHowever, you are not allowed to use the multiplication operator (*) or the exponentiation opera...
8
8
[ { "content": "Design a JavaScript function that can convert any string into a camel case version. The function should handle special characters, numbers, and multiple consecutive spaces in the input string and convert them accordingly. Additionally, the function should exclude certain words from being capitaliz...
[ { "content": "Design a JavaScript function that can convert any string into a camel case version. The function should handle special characters, numbers, and multiple consecutive spaces in the input string and convert them accordingly. Additionally, the function should exclude certain words from being capitaliz...
8
2
[ { "content": "Write a JavaScript program to check if a given string is a palindrome, but ignore any non-alphabetic characters and consider case sensitivity. The program should also handle strings with multiple sentences and should exclude any punctuation marks or special characters in addition to non-alphabetic...
[ { "content": "Write a JavaScript program to check if a given string is a palindrome, but ignore any non-alphabetic characters and consider case sensitivity. The program should also handle strings with multiple sentences and should exclude any punctuation marks or special characters in addition to non-alphabetic...
8
1
[ { "content": "Write a regular expression in JavaScript to find all hyperlinks that start with either \"http://\" or \"https://\" and end with \".com\" or \".net\" in a piece of text. Additionally, the regular expression should only match hyperlinks that have at least one subdomain and one path segment after the...
[ { "content": "Write a regular expression in JavaScript to find all hyperlinks that start with either \"http://\" or \"https://\" and end with \".com\" or \".net\" in a piece of text. Additionally, the regular expression should only match hyperlinks that have at least one subdomain and one path segment after the...
9
9
[ { "content": "Construct an algorithm that finds the minimum element in a nested array of values. The nested array can have an arbitrary number of levels, and each level can have an arbitrary number of elements. The minimum element can be any integer, positive or negative. The algorithm should be able to handle ...
[ { "content": "Construct an algorithm that finds the minimum element in a nested array of values. The nested array can have an arbitrary number of levels, and each level can have an arbitrary number of elements. The minimum element can be any integer, positive or negative. The algorithm should be able to handle ...
8
3
[ { "content": "Given a sorted array and a target value, write a function in JavaScript to search for the target value. If the target value is found, return the index of the target value in the array. If the target value is not found, return -1.\n\nAdditional Constraints:\n- You must implement the search algorith...
[ { "content": "Given a sorted array and a target value, write a function in JavaScript to search for the target value. If the target value is found, return the index of the target value in the array. If the target value is not found, return -1.\n\nAdditional Constraints:\n- You must implement the search algorith...
9
9
[ { "content": "Create a JavaScript code snippet to get the last three characters from a given string, but the string must be reversed before extracting the last three characters. Additionally, you should use a tail recursive function to solve this problem. The output should be displayed in uppercase letters. The...
[ { "content": "Create a JavaScript code snippet to get the last three characters from a given string, but the string must be reversed before extracting the last three characters. Additionally, you should use a tail recursive function to solve this problem. The output should be displayed in uppercase letters. The...
9
9
[ { "content": "Please write a JavaScript code to compare two arrays and check whether they are exactly the same or not. The arrays can contain elements of any data type and can have nested arrays as well. The code should handle cases where the arrays have different lengths or the elements are in a different orde...
[ { "content": "Please write a JavaScript code to compare two arrays and check whether they are exactly the same or not. The arrays can contain elements of any data type and can have nested arrays as well. The code should handle cases where the arrays have different lengths or the elements are in a different orde...
8
8
[ { "content": "Write a JavaScript code to hide a specific HTML element only if it has a certain class, is not a child of another specific element, and has at least one sibling element with a specific attribute value. The code should not use any external libraries or frameworks.", "role": "user" }, { ...
[ { "content": "Write a JavaScript code to hide a specific HTML element only if it has a certain class, is not a child of another specific element, and has at least one sibling element with a specific attribute value. The code should not use any external libraries or frameworks.", "role": "user" }, { ...
8
8
[ { "content": "Write a recursive function that makes a deep copy of a nested object. The function should handle objects, arrays, strings, numbers, booleans, and null values. You are not allowed to use any built-in methods or libraries for copying the object.\n\nIn addition, your function should also handle circu...
[ { "content": "Write a recursive function that makes a deep copy of a nested object. The function should handle objects, arrays, strings, numbers, booleans, and null values. You are not allowed to use any built-in methods or libraries for copying the object.\n\nIn addition, your function should also handle circu...
8
8
[ { "content": "Create a Javascript object that can generate a random list of 100 unique prime numbers between 1 and 1000, where each number appears only once in the list. Additionally, the generated list should be sorted in ascending order.", "role": "user" }, { "content": "Here's a JavaScript object...
[ { "content": "Create a Javascript object that can generate a random list of 100 unique prime numbers between 1 and 1000, where each number appears only once in the list. Additionally, the generated list should be sorted in ascending order.", "role": "user" }, { "content": "Here's a JavaScript object...
9
9
[ { "content": "Create a JavaScript function that takes a string as input and returns the current date formatted according to the string provided. The string can contain any combination of the following placeholders: \n- \"%Y\" for the full four-digit year (e.g., 2021)\n- \"%y\" for the two-digit year (e.g., 21)\...
[ { "content": "Create a JavaScript function that takes a string as input and returns the current date formatted according to the string provided. The string can contain any combination of the following placeholders: \n- \"%Y\" for the full four-digit year (e.g., 2021)\n- \"%y\" for the two-digit year (e.g., 21)\...
8
1
[ { "content": "Write a JavaScript code snippet that splits a string into an array of words. However, the code should ignore any leading or trailing white spaces in the string and should not split any words that are surrounded by double quotes. Additionally, the code should handle nested double quotes and trim an...
[ { "content": "Write a JavaScript code snippet that splits a string into an array of words. However, the code should ignore any leading or trailing white spaces in the string and should not split any words that are surrounded by double quotes. Additionally, the code should handle nested double quotes and trim an...
9
3
[ { "content": "Write a JavaScript function that takes a date as input and returns the next 5 working days (excluding weekends and public holidays) from that date. You can assume that weekends are Saturdays and Sundays. To determine public holidays, you can use an API that provides real-time data on public holida...
[ { "content": "Write a JavaScript function that takes a date as input and returns the next 5 working days (excluding weekends and public holidays) from that date. You can assume that weekends are Saturdays and Sundays. To determine public holidays, you can use an API that provides real-time data on public holida...
8
8
[ { "content": "Implement the bubble sort algorithm in JavaScript. Additionally, you need to modify the algorithm to sort the elements in descending order instead of ascending order.\n\nTo increase the difficulty, you are not allowed to use any built-in JavaScript sorting functions or methods such as `sort()`. Yo...
[ { "content": "Implement the bubble sort algorithm in JavaScript. Additionally, you need to modify the algorithm to sort the elements in descending order instead of ascending order.\n\nTo increase the difficulty, you are not allowed to use any built-in JavaScript sorting functions or methods such as `sort()`. Yo...
9
1
[ { "content": "Load the given JSON data using Javascript and validate that the \"name\" property is a string that starts with a capital letter and contains only letters and spaces, and the \"age\" property is a number between 18 and 65 (inclusive). Additionally, check that the JSON object contains an array calle...
[ { "content": "Load the given JSON data using Javascript and validate that the \"name\" property is a string that starts with a capital letter and contains only letters and spaces, and the \"age\" property is a number between 18 and 65 (inclusive). Additionally, check that the JSON object contains an array calle...
8
2