chosen
listlengths
2
2
rejected
listlengths
2
2
score_chosen
int64
6
9
score_rejected
int64
1
9
[ { "content": "Formulate a regex expression in JavaScript to verify if a given string contains only numbers and is at least 10 characters long. Additionally, the string must not contain repeating consecutive digits. Provide a piece of erroneous code that tries to solve the problem but fails.", "role": "user"...
[ { "content": "Formulate a regex expression in JavaScript to verify if a given string contains only numbers and is at least 10 characters long. Additionally, the string must not contain repeating consecutive digits. Provide a piece of erroneous code that tries to solve the problem but fails.", "role": "user"...
6
6
[ { "content": "Write a JavaScript program that generates a random number between 1000 and 10000 and checks if it is a prime number. If it is a prime number, log it to the console. If not, generate another random number between 1000 and 10000 until a prime number is generated and then log it to the console.\n\nAd...
[ { "content": "Write a JavaScript program that generates a random number between 1000 and 10000 and checks if it is a prime number. If it is a prime number, log it to the console. If not, generate another random number between 1000 and 10000 until a prime number is generated and then log it to the console.\n\nAd...
8
2
[ { "content": "Code a JavaScript function to calculate the area of a rectangle, given its length and width. However, the function should also validate that the length and width are positive integers greater than zero. If either the length or width is not a positive integer, the function should return an error me...
[ { "content": "Code a JavaScript function to calculate the area of a rectangle, given its length and width. However, the function should also validate that the length and width are positive integers greater than zero. If either the length or width is not a positive integer, the function should return an error me...
6
3
[ { "content": "Create a JavaScript function to merge two given arrays, where one array contains numbers and the other array contains strings. The merged array should alternate between numbers and strings in the same order as they appear in the original arrays. Additionally, the merged array should also include o...
[ { "content": "Create a JavaScript function to merge two given arrays, where one array contains numbers and the other array contains strings. The merged array should alternate between numbers and strings in the same order as they appear in the original arrays. Additionally, the merged array should also include o...
6
6
[ { "content": "Create a JavaScript function that converts a given number to an array of its prime factors. Additionally, the function should handle input validation, error handling, and handle numbers up to 10^12 efficiently.", "role": "user" }, { "content": "Here's a JavaScript function that convert...
[ { "content": "Create a JavaScript function that converts a given number to an array of its prime factors. Additionally, the function should handle input validation, error handling, and handle numbers up to 10^12 efficiently.", "role": "user" }, { "content": "Here's a JavaScript function that convert...
6
6
[ { "content": "Create a new array in JavaScript given an existing one and a number, but make sure that the new array does not contain any duplicate elements and is sorted in descending order. Additionally, the new array should only contain elements that are divisible by 3 and have a length greater than 5.", ...
[ { "content": "Create a new array in JavaScript given an existing one and a number, but make sure that the new array does not contain any duplicate elements and is sorted in descending order. Additionally, the new array should only contain elements that are divisible by 3 and have a length greater than 5.", ...
8
8
[ { "content": "Write a JavaScript function that takes an array of color codes as input and sets the background color of each element to the respective color code. Additionally, change the text color to white for each element.\n\nExample input: [\"#ffa11f\", \"#00ff00\", \"#0000ff\"]\n\nNote:\n- The function shou...
[ { "content": "Write a JavaScript function that takes an array of color codes as input and sets the background color of each element to the respective color code. Additionally, change the text color to white for each element.\n\nExample input: [\"#ffa11f\", \"#00ff00\", \"#0000ff\"]\n\nNote:\n- The function shou...
8
4
[ { "content": "Answer the following question: Implement a while loop in JavaScript that prints the prime numbers from 1 to 1000000 in ascending order.", "role": "user" }, { "content": "Here's an example of a while loop in JavaScript that prints the prime numbers from 1 to 1000000 in ascending order:\...
[ { "content": "Answer the following question: Implement a while loop in JavaScript that prints the prime numbers from 1 to 1000000 in ascending order.", "role": "user" }, { "content": "Here's an example of a while loop in JavaScript that prints the prime numbers from 1 to 1000000 in ascending order:\...
8
4
[ { "content": "Create a JavaScript function for sorting an array of numbers in ascending order using the merge sort algorithm. The time complexity of the sorting function should be O(n log n) and the space complexity should be O(n). Do not use any built-in sorting functions or libraries. Additionally, you are no...
[ { "content": "Create a JavaScript function for sorting an array of numbers in ascending order using the merge sort algorithm. The time complexity of the sorting function should be O(n log n) and the space complexity should be O(n). Do not use any built-in sorting functions or libraries. Additionally, you are no...
7
7
[ { "content": "Given an array of integers, find the top k maximum values in the array and output them in descending order in JavaScript. However, you are not allowed to use any built-in JavaScript functions or methods that directly solve this problem, such as Math.max() or Array.prototype.reduce(). You must impl...
[ { "content": "Given an array of integers, find the top k maximum values in the array and output them in descending order in JavaScript. However, you are not allowed to use any built-in JavaScript functions or methods that directly solve this problem, such as Math.max() or Array.prototype.reduce(). You must impl...
6
4
[ { "content": "Create a function in JavaScript to check if a given number is a prime number. The function should also return the next prime number if the given number is not prime. Additionally, the function should handle input validation to ensure that the provided number is a positive integer.", "role": "u...
[ { "content": "Create a function in JavaScript to check if a given number is a prime number. The function should also return the next prime number if the given number is not prime. Additionally, the function should handle input validation to ensure that the provided number is a positive integer.", "role": "u...
9
9
[ { "content": "Given a string variable, write a function to convert it to uppercase without using any built-in string manipulation functions or methods in JavaScript. Additionally, the function should handle special characters and maintain their positions in the converted string. The function should also have a ...
[ { "content": "Given a string variable, write a function to convert it to uppercase without using any built-in string manipulation functions or methods in JavaScript. Additionally, the function should handle special characters and maintain their positions in the converted string. The function should also have a ...
9
2
[ { "content": "Write a JavaScript program to find out the day of the week for a given date, taking into account the Julian calendar system. However, you cannot use any built-in date/time functions or libraries in your solution.\n\nAdditionally, you must implement the algorithm to handle the complex leap year rul...
[ { "content": "Write a JavaScript program to find out the day of the week for a given date, taking into account the Julian calendar system. However, you cannot use any built-in date/time functions or libraries in your solution.\n\nAdditionally, you must implement the algorithm to handle the complex leap year rul...
9
9
[ { "content": "Please write a JavaScript function that dynamically creates a form with the following requirements:\n\n1. The form should have a unique ID generated randomly.\n2. The form should have a class named \"custom-form\".\n3. The form should contain the following elements:\n a. An input field with a ty...
[ { "content": "Please write a JavaScript function that dynamically creates a form with the following requirements:\n\n1. The form should have a unique ID generated randomly.\n2. The form should have a class named \"custom-form\".\n3. The form should contain the following elements:\n a. An input field with a ty...
7
1
[ { "content": "Create a JavaScript function that takes a sentence as a parameter and replaces all occurrences of a given word with another word. The function should also keep track of the number of replacements made and return it as part of the output. The function should have a time complexity of O(n), where n ...
[ { "content": "Create a JavaScript function that takes a sentence as a parameter and replaces all occurrences of a given word with another word. The function should also keep track of the number of replacements made and return it as part of the output. The function should have a time complexity of O(n), where n ...
6
3
[ { "content": "Create a JavaScript function to convert a given string to a Base-64 encoded value. The function should only use built-in string manipulation methods and should not utilize any third-party libraries or modules. The input string will always consist of alphanumeric characters and may include special ...
[ { "content": "Create a JavaScript function to convert a given string to a Base-64 encoded value. The function should only use built-in string manipulation methods and should not utilize any third-party libraries or modules. The input string will always consist of alphanumeric characters and may include special ...
9
3
[ { "content": "Write a JavaScript program to create a random string of 20 characters, where each character must be a unique lowercase letter or number. The string must not contain any duplicate characters. Additionally, the string must be generated in such a way that the sum of the ASCII values of all the charac...
[ { "content": "Write a JavaScript program to create a random string of 20 characters, where each character must be a unique lowercase letter or number. The string must not contain any duplicate characters. Additionally, the string must be generated in such a way that the sum of the ASCII values of all the charac...
8
4
[ { "content": "Create a JavaScript function that checks if a given string is a palindrome, considering the following rules:\n1. The given string must contain only alphanumeric characters (letters and numbers).\n2. The function should ignore any leading or trailing whitespace characters in the string.\n3. The fun...
[ { "content": "Create a JavaScript function that checks if a given string is a palindrome, considering the following rules:\n1. The given string must contain only alphanumeric characters (letters and numbers).\n2. The function should ignore any leading or trailing whitespace characters in the string.\n3. The fun...
9
9
[ { "content": "Create an AJAX request in JavaScript to retrieve data from the following URL: http://www.example.com/data. The response should be parsed as JSON and displayed in a table format on the webpage. Additionally, implement error handling to display an appropriate message if the request fails or the retu...
[ { "content": "Create an AJAX request in JavaScript to retrieve data from the following URL: http://www.example.com/data. The response should be parsed as JSON and displayed in a table format on the webpage. Additionally, implement error handling to display an appropriate message if the request fails or the retu...
9
2
[ { "content": "Write a JavaScript function that takes an array of numbers as input and returns a new array containing only the prime numbers. The function should use a variable with a specific scoping technique to optimize the performance of the algorithm. Additionally, explain the differences between the var, l...
[ { "content": "Write a JavaScript function that takes an array of numbers as input and returns a new array containing only the prime numbers. The function should use a variable with a specific scoping technique to optimize the performance of the algorithm. Additionally, explain the differences between the var, l...
9
2
[ { "content": "Write a JavaScript function that takes in two numbers as input and returns a boolean value indicating if the first number is divisible by the second number without any remainder. Additionally, if the second number is equal to zero, the function should throw an error with a custom error message ind...
[ { "content": "Write a JavaScript function that takes in two numbers as input and returns a boolean value indicating if the first number is divisible by the second number without any remainder. Additionally, if the second number is equal to zero, the function should throw an error with a custom error message ind...
9
9
[ { "content": "Create a function in JavaScript that takes an array as input and returns a new array containing only the unique values from the original array. The input array can contain both numbers and strings. The function should have a time complexity of O(n) and a space complexity of O(n). Additionally, the...
[ { "content": "Create a function in JavaScript that takes an array as input and returns a new array containing only the unique values from the original array. The input array can contain both numbers and strings. The function should have a time complexity of O(n) and a space complexity of O(n). Additionally, the...
7
3
[ { "content": "Obtain the parameter names from a given JavaScript function, where the function must have at least 3 parameters and the parameter names must be in reverse alphabetical order. The function should also check for duplicate parameter names and return an error if any duplicates are found. Additionally,...
[ { "content": "Obtain the parameter names from a given JavaScript function, where the function must have at least 3 parameters and the parameter names must be in reverse alphabetical order. The function should also check for duplicate parameter names and return an error if any duplicates are found. Additionally,...
9
9
[ { "content": "Write a JavaScript code snippet that displays the Fibonacci sequence up to the nth term on the webpage, where n is a positive integer provided by the user. However, you are not allowed to use recursion or the formula for calculating Fibonacci numbers. You must implement the Fibonacci sequence usin...
[ { "content": "Write a JavaScript code snippet that displays the Fibonacci sequence up to the nth term on the webpage, where n is a positive integer provided by the user. However, you are not allowed to use recursion or the formula for calculating Fibonacci numbers. You must implement the Fibonacci sequence usin...
7
3
[ { "content": "Create a JavaScript code to find the frequency of each unique vowel in a string, excluding any special characters or whitespace. The code should output the result in descending order of character frequency.\n\nErroneous code reference:\n\n```javascript\nfunction findVowelFrequency(str) {\n let vo...
[ { "content": "Create a JavaScript code to find the frequency of each unique vowel in a string, excluding any special characters or whitespace. The code should output the result in descending order of character frequency.\n\nErroneous code reference:\n\n```javascript\nfunction findVowelFrequency(str) {\n let vo...
9
9
[ { "content": "Create a JavaScript Object for a Student with key-value pairs for their id, name, nationality, and age. Additionally, ensure that the id is a unique identifier and cannot be changed once set. Implement a method that calculates and stores the average grade of the student, where the grade is a numbe...
[ { "content": "Create a JavaScript Object for a Student with key-value pairs for their id, name, nationality, and age. Additionally, ensure that the id is a unique identifier and cannot be changed once set. Implement a method that calculates and stores the average grade of the student, where the grade is a numbe...
7
7
[ { "content": "Given a JSON string, parse the string and convert it into an object. The JSON string may contain nested objects and arrays. Additionally, the JSON string may contain complex data types such as dates and custom objects.\n\n1. First, initialize an empty object to store the parsed JSON.\n2. Iterate t...
[ { "content": "Given a JSON string, parse the string and convert it into an object. The JSON string may contain nested objects and arrays. Additionally, the JSON string may contain complex data types such as dates and custom objects.\n\n1. First, initialize an empty object to store the parsed JSON.\n2. Iterate t...
8
4
[ { "content": "Write a function in JavaScript that takes in two operands and checks if their values and types are equal or not. The function should return a boolean value indicating the result. You are not allowed to use any built-in comparison operators such as `==` or `===`. Additionally, you are not allowed t...
[ { "content": "Write a function in JavaScript that takes in two operands and checks if their values and types are equal or not. The function should return a boolean value indicating the result. You are not allowed to use any built-in comparison operators such as `==` or `===`. Additionally, you are not allowed t...
6
4
[ { "content": "Given a string and an array of strings, write a JavaScript code snippet to check if the string is an anagram of any string in the array. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. \n\nTo solve this problem, you can follow these steps:\n1. Create a f...
[ { "content": "Given a string and an array of strings, write a JavaScript code snippet to check if the string is an anagram of any string in the array. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. \n\nTo solve this problem, you can follow these steps:\n1. Create a f...
7
3
[ { "content": "Create a JavaScript function to validate if a given string is a valid URL. The function should check if the URL has at least one query parameter, if the domain name is a valid registered domain, and if the URL is using a secure protocol (https).\n\nAdditionally, the function should handle cases wh...
[ { "content": "Create a JavaScript function to validate if a given string is a valid URL. The function should check if the URL has at least one query parameter, if the domain name is a valid registered domain, and if the URL is using a secure protocol (https).\n\nAdditionally, the function should handle cases wh...
9
9
[ { "content": "Write a JavaScript function that takes an argument and determines whether it is prime or composite. However, you cannot use any built-in functions or libraries to determine the primality of the number. The function should have a time complexity of O(sqrt(n)), where n is the input number.", "ro...
[ { "content": "Write a JavaScript function that takes an argument and determines whether it is prime or composite. However, you cannot use any built-in functions or libraries to determine the primality of the number. The function should have a time complexity of O(sqrt(n)), where n is the input number.", "ro...
8
8
[ { "content": "Create a valid JavaScript array of objects containing the four elements \"name\", \"age\", \"gender\", and \"hobbies\". Each object should have a randomly generated name, age between 18 and 60, gender (either \"male\" or \"female\"), and an array of randomly generated hobbies (minimum 1 and maximu...
[ { "content": "Create a valid JavaScript array of objects containing the four elements \"name\", \"age\", \"gender\", and \"hobbies\". Each object should have a randomly generated name, age between 18 and 60, gender (either \"male\" or \"female\"), and an array of randomly generated hobbies (minimum 1 and maximu...
8
4
[ { "content": "Using a unique function in JavaScript, remove the duplicate values in the given array. However, you are not allowed to use any built-in JavaScript functions or libraries to achieve this. You must implement the removal of duplicates yourself.\n\nFurthermore, you must use constant space complexity O...
[ { "content": "Using a unique function in JavaScript, remove the duplicate values in the given array. However, you are not allowed to use any built-in JavaScript functions or libraries to achieve this. You must implement the removal of duplicates yourself.\n\nFurthermore, you must use constant space complexity O...
8
8
[ { "content": "Write a JavaScript function that takes two positive integers as parameters and returns their sum. The function should be named \"addNumbers\".\n\nThe function should only accept positive integers greater than 1 as inputs. If the input is not a positive integer or it is less than or equal to 1, the...
[ { "content": "Write a JavaScript function that takes two positive integers as parameters and returns their sum. The function should be named \"addNumbers\".\n\nThe function should only accept positive integers greater than 1 as inputs. If the input is not a positive integer or it is less than or equal to 1, the...
9
4
[ { "content": "Change the variable \"str\" below to upper case, but without using any built-in string manipulation methods. Additionally, handle the case where the string contains special characters and numbers. Ensure that the solution has a time complexity of O(n) and a space complexity of O(1).\n\nlet str = '...
[ { "content": "Change the variable \"str\" below to upper case, but without using any built-in string manipulation methods. Additionally, handle the case where the string contains special characters and numbers. Ensure that the solution has a time complexity of O(n) and a space complexity of O(1).\n\nlet str = '...
8
8
[ { "content": "Implement a \"while\" loop in JavaScript that prints all prime numbers between 1 and 1000, but you are not allowed to use any built-in functions or libraries for prime number generation or checking. You need to implement your own logic for determining whether a number is prime or not.", "role"...
[ { "content": "Implement a \"while\" loop in JavaScript that prints all prime numbers between 1 and 1000, but you are not allowed to use any built-in functions or libraries for prime number generation or checking. You need to implement your own logic for determining whether a number is prime or not.", "role"...
7
7
[ { "content": "Reverse the elements of a given linked list in groups of size K without using any additional storage. The input linked list should be modified in-place.\n\nstruct Node {\n int data;\n struct Node* next;\n};\n\nstruct Node* reverseInGroups(struct Node* head, int K);\n\n// Example usage:\nstru...
[ { "content": "Reverse the elements of a given linked list in groups of size K without using any additional storage. The input linked list should be modified in-place.\n\nstruct Node {\n int data;\n struct Node* next;\n};\n\nstruct Node* reverseInGroups(struct Node* head, int K);\n\n// Example usage:\nstru...
7
2
[ { "content": "Write a JavaScript function to get the Nth element from the end of a given array. The array can contain both numbers and strings.\n\nThe function should handle the following cases:\n1. If the array is empty, return null.\n2. If the array length is less than N, return null.\n3. If N is negative, re...
[ { "content": "Write a JavaScript function to get the Nth element from the end of a given array. The array can contain both numbers and strings.\n\nThe function should handle the following cases:\n1. If the array is empty, return null.\n2. If the array length is less than N, return null.\n3. If N is negative, re...
9
9
[ { "content": "Construct a JavaScript program to create an alert message when a button is clicked. Additionally, the program should also display a confirmation message before the alert message is shown. The confirmation message should include the option to cancel the alert message.\n\nFurthermore, the program sh...
[ { "content": "Construct a JavaScript program to create an alert message when a button is clicked. Additionally, the program should also display a confirmation message before the alert message is shown. The confirmation message should include the option to cancel the alert message.\n\nFurthermore, the program sh...
7
7
[ { "content": "Increase the difficulty of the given programming test question by considering nested objects within the given objects and implementing a recursive algorithm.\n\nWrite a program that compares two given objects and outputs the differences. The program should check if the objects have the same number...
[ { "content": "Increase the difficulty of the given programming test question by considering nested objects within the given objects and implementing a recursive algorithm.\n\nWrite a program that compares two given objects and outputs the differences. The program should check if the objects have the same number...
8
8
[ { "content": "Create a looping structure in JavaScript that executes a task 100 times, but only if a certain condition is met. The condition is that the task should only be executed if the sum of all the prime numbers from 1 to 100 (inclusive) is divisible by 7.\n\n#Erroneous Code Example#\n```javascript\nlet s...
[ { "content": "Create a looping structure in JavaScript that executes a task 100 times, but only if a certain condition is met. The condition is that the task should only be executed if the sum of all the prime numbers from 1 to 100 (inclusive) is divisible by 7.\n\n#Erroneous Code Example#\n```javascript\nlet s...
7
4
[ { "content": "Generate a function \"capitalize\" in JavaScript to capitalize the first letter of every word, but exclude the words \"a\", \"an\", \"the\", \"and\", \"but\", \"or\", \"for\", \"nor\", \"on\", \"at\", \"to\", \"from\", and \"by\" from being capitalized. The function should also handle special char...
[ { "content": "Generate a function \"capitalize\" in JavaScript to capitalize the first letter of every word, but exclude the words \"a\", \"an\", \"the\", \"and\", \"but\", \"or\", \"for\", \"nor\", \"on\", \"at\", \"to\", \"from\", and \"by\" from being capitalized. The function should also handle special char...
9
9
[ { "content": "Write a JavaScript function that returns the first 500 prime numbers greater than 10,000.\n\n#Difficulty Increase Reasoning#\nBy increasing the starting point of prime numbers to be greater than 10,000, the difficulty of the programming test question is further increased. This requires an even mor...
[ { "content": "Write a JavaScript function that returns the first 500 prime numbers greater than 10,000.\n\n#Difficulty Increase Reasoning#\nBy increasing the starting point of prime numbers to be greater than 10,000, the difficulty of the programming test question is further increased. This requires an even mor...
7
7
[ { "content": "Write a JavaScript function that calculates the factorial of a given number and returns the result as a string with the thousands separator.\n\nNote: The factorial of a number is the product of all positive integers less than or equal to that number. For example, the factorial of 5 is 5 * 4 * 3 * ...
[ { "content": "Write a JavaScript function that calculates the factorial of a given number and returns the result as a string with the thousands separator.\n\nNote: The factorial of a number is the product of all positive integers less than or equal to that number. For example, the factorial of 5 is 5 * 4 * 3 * ...
6
4
[ { "content": "Suggest code to check if an object has a given property and its value is equal to a specific value. The object can have nested properties and the code should be able to handle multiple levels of nesting.\n\nFor example, consider the following object:\nobject = {\n id: 1,\n name: 'John',\n addre...
[ { "content": "Suggest code to check if an object has a given property and its value is equal to a specific value. The object can have nested properties and the code should be able to handle multiple levels of nesting.\n\nFor example, consider the following object:\nobject = {\n id: 1,\n name: 'John',\n addre...
9
9
[ { "content": "Create a React component that displays a form with three text input fields. The component should also include a submit button that is disabled until all three input fields have at least 6 characters. Additionally, the component should include client-side validation to ensure that the input fields ...
[ { "content": "Create a React component that displays a form with three text input fields. The component should also include a submit button that is disabled until all three input fields have at least 6 characters. Additionally, the component should include client-side validation to ensure that the input fields ...
8
8
[ { "content": "Write a JavaScript program to implement the bubble sort algorithm for sorting an array of numbers. The program should also include a function to reverse the sorted array. The array should have a length of at least 5 and at most 100. The program should handle duplicate numbers in the array and sort...
[ { "content": "Write a JavaScript program to implement the bubble sort algorithm for sorting an array of numbers. The program should also include a function to reverse the sorted array. The array should have a length of at least 5 and at most 100. The program should handle duplicate numbers in the array and sort...
7
1
[ { "content": "Write a function in JavaScript that accepts two numbers as input and returns their difference using bitwise operators. The function should handle numbers of any type, including positive and negative integers, floating-point numbers, and numbers in scientific notation. It should also handle edge ca...
[ { "content": "Write a function in JavaScript that accepts two numbers as input and returns their difference using bitwise operators. The function should handle numbers of any type, including positive and negative integers, floating-point numbers, and numbers in scientific notation. It should also handle edge ca...
6
6
[ { "content": "Modify the following Javascript code to check if a given number is a twin prime or not. A twin prime is a prime number that is either 3 less or 3 more than another prime number. Additionally, the code should also check if the given number is a perfect square and a palindrome.", "role": "user" ...
[ { "content": "Modify the following Javascript code to check if a given number is a twin prime or not. A twin prime is a prime number that is either 3 less or 3 more than another prime number. Additionally, the code should also check if the given number is a perfect square and a palindrome.", "role": "user" ...
8
8
[ { "content": "## Problem ##\n\nGiven an array of numbers, filter the array so that only the prime numbers remain. Return the filtered array.\n\nWrite a function `filterPrimeNumbers`:\n\n```\nfunction filterPrimeNumbers(arr: number[]): number[] {\n // code here\n}\n```\n\n**Input**\n- An array of integers, `arr...
[ { "content": "## Problem ##\n\nGiven an array of numbers, filter the array so that only the prime numbers remain. Return the filtered array.\n\nWrite a function `filterPrimeNumbers`:\n\n```\nfunction filterPrimeNumbers(arr: number[]): number[] {\n // code here\n}\n```\n\n**Input**\n- An array of integers, `arr...
7
7
[ { "content": "Create a React component that allows the user to input their name. When the user clicks a button, display a greeting message that includes the user's name and the current date and time. The greeting message should be styled with CSS to have a background color and a border. Additionally, add a coun...
[ { "content": "Create a React component that allows the user to input their name. When the user clicks a button, display a greeting message that includes the user's name and the current date and time. The greeting message should be styled with CSS to have a background color and a border. Additionally, add a coun...
8
4
[ { "content": "Rewrite the following JavaScript code such that it prints the numbers 1 to 10, but this time, every odd number should be squared before printing. Additionally, ensure that the code uses a recursive function to calculate the squares of odd numbers. Furthermore, implement the solution in a way that ...
[ { "content": "Rewrite the following JavaScript code such that it prints the numbers 1 to 10, but this time, every odd number should be squared before printing. Additionally, ensure that the code uses a recursive function to calculate the squares of odd numbers. Furthermore, implement the solution in a way that ...
8
2
[ { "content": "Sort the books in alphabetical order using JavaScript. The array of books contains strings with random characters and numbers in addition to the book titles. However, the sorting should be case-sensitive and numbers should come before letters in the sorted result. If two books have the same starti...
[ { "content": "Sort the books in alphabetical order using JavaScript. The array of books contains strings with random characters and numbers in addition to the book titles. However, the sorting should be case-sensitive and numbers should come before letters in the sorted result. If two books have the same starti...
6
6
[ { "content": "Transform the given code into an array of objects in JavaScript, ensuring that each object contains properties for name and age. Additionally, each name must be a string and each age must be a positive integer. However, you should also validate that the age is within a specific range, such as betw...
[ { "content": "Transform the given code into an array of objects in JavaScript, ensuring that each object contains properties for name and age. Additionally, each name must be a string and each age must be a positive integer. However, you should also validate that the age is within a specific range, such as betw...
6
6
[ { "content": "Create a JavaScript function which takes a string and returns the longest word in it, excluding any words that contain the letter \"z\". The function should have a time complexity of O(n), where n is the length of the string, and a space complexity of O(1).", "role": "user" }, { "conte...
[ { "content": "Create a JavaScript function which takes a string and returns the longest word in it, excluding any words that contain the letter \"z\". The function should have a time complexity of O(n), where n is the length of the string, and a space complexity of O(1).", "role": "user" }, { "conte...
9
1
[ { "content": "Write a function in Javascript to return the k-th highest number in an array, where k is a parameter passed to the function. The function should also handle cases where k is larger than the size of the array. Additionally, the function should return an error if the array contains duplicate numbers...
[ { "content": "Write a function in Javascript to return the k-th highest number in an array, where k is a parameter passed to the function. The function should also handle cases where k is larger than the size of the array. Additionally, the function should return an error if the array contains duplicate numbers...
8
2
[ { "content": "Write a JavaScript program to group an array of objects based on a property and sum up the values of the grouped objects. Each object in the array will now also have a \"department\" property. Additionally, the program should only sum up the values of objects whose salary is above a certain thresh...
[ { "content": "Write a JavaScript program to group an array of objects based on a property and sum up the values of the grouped objects. Each object in the array will now also have a \"department\" property. Additionally, the program should only sum up the values of objects whose salary is above a certain thresh...
8
2
[ { "content": "Write a JavaScript function that returns the current date and time in the format \"Wednesday, November 20, 2019 10:30 AM\". The function should also include the day of the week, the month name, and the 12-hour time format with AM/PM indicators.\n\nThe function should accept an optional parameter t...
[ { "content": "Write a JavaScript function that returns the current date and time in the format \"Wednesday, November 20, 2019 10:30 AM\". The function should also include the day of the week, the month name, and the 12-hour time format with AM/PM indicators.\n\nThe function should accept an optional parameter t...
8
8
[ { "content": "Rewritten Test:\n\nWhat is the output of the following code? What is the space complexity of this function?\n\nfunction bar(arr) {\n let result = [];\n for (let i = 0; i < arr.length; i++) {\n for (let j = i + 1; j < arr.length; j++) {\n if (arr[i] + arr[j] === 0) {\n result.push(...
[ { "content": "Rewritten Test:\n\nWhat is the output of the following code? What is the space complexity of this function?\n\nfunction bar(arr) {\n let result = [];\n for (let i = 0; i < arr.length; i++) {\n for (let j = i + 1; j < arr.length; j++) {\n if (arr[i] + arr[j] === 0) {\n result.push(...
8
2
[ { "content": "Compose a JavaScript code to find the sum of all prime numbers in the range from 1 to 1000000.", "role": "user" }, { "content": "Here is the JavaScript code to find the sum of all prime numbers in the range from 1 to 1000000:\n\n```javascript\nfunction isPrime(num) {\n if (num <= 1) r...
[ { "content": "Compose a JavaScript code to find the sum of all prime numbers in the range from 1 to 1000000.", "role": "user" }, { "content": "Here is the JavaScript code to find the sum of all prime numbers in the range from 1 to 1000000:\n\n```javascript\nfunction isPrime(num) {\n if (num <= 1) r...
6
6
[ { "content": "Write a JavaScript function that takes a string and an array of strings. Return an array with elements from the string filtered by the array of strings provided. The function should have a time complexity of O(n^3), where n is the length of the string.\n\nErroneous code example:\n```javascript\nfu...
[ { "content": "Write a JavaScript function that takes a string and an array of strings. Return an array with elements from the string filtered by the array of strings provided. The function should have a time complexity of O(n^3), where n is the length of the string.\n\nErroneous code example:\n```javascript\nfu...
7
2
[ { "content": "Write a JavaScript function that takes in an array of strings as a parameter and prints only the palindromic strings in ascending order. The function should ignore any non-string values in the array. Additionally, the function should return the sum of the lengths of all palindromic strings in the ...
[ { "content": "Write a JavaScript function that takes in an array of strings as a parameter and prints only the palindromic strings in ascending order. The function should ignore any non-string values in the array. Additionally, the function should return the sum of the lengths of all palindromic strings in the ...
8
8
[ { "content": "Write a JavaScript function that reverses a given array without using the built-in reverse() method. The function should also handle arrays that contain nested arrays or objects as elements. The function should have a time complexity of O(n^2 * m), where n is the length of the input array and m is...
[ { "content": "Write a JavaScript function that reverses a given array without using the built-in reverse() method. The function should also handle arrays that contain nested arrays or objects as elements. The function should have a time complexity of O(n^2 * m), where n is the length of the input array and m is...
7
4
[ { "content": "In a React.js application, how would you set the state object 'userData' to an empty object, and then update it with a new key-value pair? Additionally, you must ensure that the new key is unique and not already present in the 'userData' object. However, you are not allowed to use the built-in sta...
[ { "content": "In a React.js application, how would you set the state object 'userData' to an empty object, and then update it with a new key-value pair? Additionally, you must ensure that the new key is unique and not already present in the 'userData' object. However, you are not allowed to use the built-in sta...
7
7
[ { "content": "Write a JavaScript program to extract the domain name from a given URL, ensuring that the URL is valid, contains at least one subdomain, and does not use any built-in JavaScript functions or regular expressions. Additionally, optimize the program to have a time complexity of O(n) and a space compl...
[ { "content": "Write a JavaScript program to extract the domain name from a given URL, ensuring that the URL is valid, contains at least one subdomain, and does not use any built-in JavaScript functions or regular expressions. Additionally, optimize the program to have a time complexity of O(n) and a space compl...
7
3
[ { "content": "Design a JavaScript function that checks if a number is between -1000 and 1000, inclusive, and is divisible by both 5 and 3. Additionally, the function should also check if the number is a perfect square and is not divisible by 7.", "role": "user" }, { "content": "Here is a JavaScript ...
[ { "content": "Design a JavaScript function that checks if a number is between -1000 and 1000, inclusive, and is divisible by both 5 and 3. Additionally, the function should also check if the number is a perfect square and is not divisible by 7.", "role": "user" }, { "content": "Here is a JavaScript ...
9
2
[ { "content": "Write a JavaScript function to check if a given key already exists in an object. However, you are not allowed to use the `in` operator, the `hasOwnProperty()` method, or any other built-in JavaScript method to check for the existence of the key. Instead, you must implement your own custom method t...
[ { "content": "Write a JavaScript function to check if a given key already exists in an object. However, you are not allowed to use the `in` operator, the `hasOwnProperty()` method, or any other built-in JavaScript method to check for the existence of the key. Instead, you must implement your own custom method t...
7
7
[ { "content": "Convert the following array of strings to an array of integers using JavaScript. The conversion should be done without using any built-in JavaScript functions or methods that directly convert strings to integers. The resulting array should only contain integers that are greater than 100. The time ...
[ { "content": "Convert the following array of strings to an array of integers using JavaScript. The conversion should be done without using any built-in JavaScript functions or methods that directly convert strings to integers. The resulting array should only contain integers that are greater than 100. The time ...
6
6
[ { "content": "Create a JavaScript script to toggle a class on the page, but instead of toggling the class on all elements with a specific attribute, toggle the class on all child elements of a specific parent element. The script should also add a delay of 500 milliseconds before toggling the class and should on...
[ { "content": "Create a JavaScript script to toggle a class on the page, but instead of toggling the class on all elements with a specific attribute, toggle the class on all child elements of a specific parent element. The script should also add a delay of 500 milliseconds before toggling the class and should on...
8
8
[ { "content": "Write a JavaScript program to remove all characters from a string that appear more than three times consecutively. If a character appears exactly three times consecutively, it should be kept in the final result. \n\nstring = \"abbbccdddeee\"", "role": "user" }, { "content": "Here is a ...
[ { "content": "Write a JavaScript program to remove all characters from a string that appear more than three times consecutively. If a character appears exactly three times consecutively, it should be kept in the final result. \n\nstring = \"abbbccdddeee\"", "role": "user" }, { "content": "Here is a ...
6
2
[ { "content": "Design an API endpoint that takes an array of numbers and returns the sum of all the even numbers in the array using JavaScript.\n\nThe API endpoint should validate the input array to ensure it is an array of numbers, with a length between 1 and 10^6. If the input is not valid, the endpoint should...
[ { "content": "Design an API endpoint that takes an array of numbers and returns the sum of all the even numbers in the array using JavaScript.\n\nThe API endpoint should validate the input array to ensure it is an array of numbers, with a length between 1 and 10^6. If the input is not valid, the endpoint should...
6
4
[ { "content": "Write a JavaScript program to calculate the total savings of an individual over a specified number of years, given the annual deposits, annual interest rate, and the frequency of compounding. Assume the interest is compounded annually by default.\n\nExample:\ndeposits = $1000\nrate = 5%\nyears = 1...
[ { "content": "Write a JavaScript program to calculate the total savings of an individual over a specified number of years, given the annual deposits, annual interest rate, and the frequency of compounding. Assume the interest is compounded annually by default.\n\nExample:\ndeposits = $1000\nrate = 5%\nyears = 1...
9
4
[ { "content": "Generate an object using JavaScript that contains all prime numbers from 1 to 1000 and their corresponding factors.\n\nNote: The factors should be stored in an array for each prime number.", "role": "user" }, { "content": "Here's a code snippet that generates an object containing all p...
[ { "content": "Generate an object using JavaScript that contains all prime numbers from 1 to 1000 and their corresponding factors.\n\nNote: The factors should be stored in an array for each prime number.", "role": "user" }, { "content": "Here's a code snippet that generates an object containing all p...
6
3
[ { "content": "Write HTML and JavaScript code to create a dynamic table that allows users to add and remove rows. The table should contain the following information: Name (maximum length of 50 characters), Age (between 18 and 100), Gender (either Male or Female), and a button to delete the row. Additionally, imp...
[ { "content": "Write HTML and JavaScript code to create a dynamic table that allows users to add and remove rows. The table should contain the following information: Name (maximum length of 50 characters), Age (between 18 and 100), Gender (either Male or Female), and a button to delete the row. Additionally, imp...
9
9
[ { "content": "Create a JavaScript code snippet to get a list of all the prime numbers in an array. The code should only consider numbers greater than 1 as potential prime numbers. Additionally, handle the case if the input array is empty and return an appropriate error message. Furthermore, ensure that the code...
[ { "content": "Create a JavaScript code snippet to get a list of all the prime numbers in an array. The code should only consider numbers greater than 1 as potential prime numbers. Additionally, handle the case if the input array is empty and return an appropriate error message. Furthermore, ensure that the code...
9
9
[ { "content": "Create an HTML form containing four text inputs: Name, Email, Phone Number, and Address. Add a button that triggers a JavaScript function to validate the form. The validation function should check if all fields are filled out correctly. \n\nFor the Name field, the validation function should check ...
[ { "content": "Create an HTML form containing four text inputs: Name, Email, Phone Number, and Address. Add a button that triggers a JavaScript function to validate the form. The validation function should check if all fields are filled out correctly. \n\nFor the Name field, the validation function should check ...
9
2
[ { "content": "Define a function in JavaScript that returns true if a given number is a prime number greater than 100 and a multiple of 7.", "role": "user" }, { "content": "Here's an example of a JavaScript function that checks if a given number is a prime number greater than 100 and a multiple of 7:...
[ { "content": "Define a function in JavaScript that returns true if a given number is a prime number greater than 100 and a multiple of 7.", "role": "user" }, { "content": "Here's an example of a JavaScript function that checks if a given number is a prime number greater than 100 and a multiple of 7:...
7
4
[ { "content": "Create a JavaScript function that generates a random number between 1 and 1000, and returns the sum of all the digits in the generated number. However, you are not allowed to use any built-in JavaScript functions or methods to convert the number into a string or manipulate the digits individually....
[ { "content": "Create a JavaScript function that generates a random number between 1 and 1000, and returns the sum of all the digits in the generated number. However, you are not allowed to use any built-in JavaScript functions or methods to convert the number into a string or manipulate the digits individually....
7
7
[ { "content": "Write a JavaScript function that takes in a string as input and returns the total number of unique non-whitespace characters in the string. The function should ignore any leading or trailing whitespace and should only count characters within the string itself. The input string can contain alphanum...
[ { "content": "Write a JavaScript function that takes in a string as input and returns the total number of unique non-whitespace characters in the string. The function should ignore any leading or trailing whitespace and should only count characters within the string itself. The input string can contain alphanum...
6
6
[ { "content": "Write a JavaScript program that prints all the prime numbers from 0 to a given number n, with a time complexity of O(n*log(log(n))).\n\nn = 100", "role": "user" }, { "content": "Here's a JavaScript program that prints all the prime numbers from 0 to a given number `n` with a time compl...
[ { "content": "Write a JavaScript program that prints all the prime numbers from 0 to a given number n, with a time complexity of O(n*log(log(n))).\n\nn = 100", "role": "user" }, { "content": "Here's a JavaScript program that prints all the prime numbers from 0 to a given number `n` with a time compl...
6
6
[ { "content": "Suggest a JavaScript code to generate a random alphanumeric string of length N that contains at least one uppercase letter, one lowercase letter, one digit, and one special character. The code should be optimized to have a time complexity of O(N log N) and a space complexity of O(N).\n\nAdditional...
[ { "content": "Suggest a JavaScript code to generate a random alphanumeric string of length N that contains at least one uppercase letter, one lowercase letter, one digit, and one special character. The code should be optimized to have a time complexity of O(N log N) and a space complexity of O(N).\n\nAdditional...
7
1
[ { "content": "Write a JavaScript program to find the greatest common divisor (GCD) of two given positive numbers, while also keeping track of the number of recursive calls made during the calculation.\nThe program should have a time complexity of O(log min(x, y)) and a space complexity of O(log min(x, y)).\nx =...
[ { "content": "Write a JavaScript program to find the greatest common divisor (GCD) of two given positive numbers, while also keeping track of the number of recursive calls made during the calculation.\nThe program should have a time complexity of O(log min(x, y)) and a space complexity of O(log min(x, y)).\nx =...
6
6
[ { "content": "Generate a random string in JavaScript of length 15 containing only characters from 'A' to 'Z' and '0' to '9'. The generated string should start with a letter, end with a number, and have at least one special character (!@#$%^&*).\n\nAdditionally, the solution should have a time complexity of O(n)...
[ { "content": "Generate a random string in JavaScript of length 15 containing only characters from 'A' to 'Z' and '0' to '9'. The generated string should start with a letter, end with a number, and have at least one special character (!@#$%^&*).\n\nAdditionally, the solution should have a time complexity of O(n)...
9
2
[ { "content": "Given a positive integer n, can you write a JavaScript program to find the sum of all the prime numbers that are greater than or equal to 2 and less than n? Your program should also output the largest prime number found. Additionally, you should optimize your solution to have a time complexity of ...
[ { "content": "Given a positive integer n, can you write a JavaScript program to find the sum of all the prime numbers that are greater than or equal to 2 and less than n? Your program should also output the largest prime number found. Additionally, you should optimize your solution to have a time complexity of ...
6
3
[ { "content": "Please provide a complete HTML code snippet to create a registration form with the following requirements:\n\n1. The form should have a title displayed at the top.\n2. The form should include at least ten different types of input fields (e.g., text, number, email, password, date, dropdown, radio b...
[ { "content": "Please provide a complete HTML code snippet to create a registration form with the following requirements:\n\n1. The form should have a title displayed at the top.\n2. The form should include at least ten different types of input fields (e.g., text, number, email, password, date, dropdown, radio b...
8
3
[ { "content": "What is the syntax to return the total number of unique elements in an array using JavaScript, without using any built-in array methods or objects, in O(n) time complexity? Additionally, you should implement the solution using a recursive function with a maximum depth of 5 levels.", "role": "u...
[ { "content": "What is the syntax to return the total number of unique elements in an array using JavaScript, without using any built-in array methods or objects, in O(n) time complexity? Additionally, you should implement the solution using a recursive function with a maximum depth of 5 levels.", "role": "u...
6
4
[ { "content": "Design a JavaScript function named \"calculate\" that calculates the median of a given array. The array can contain both numbers and strings. The function should ignore any non-numeric values in the array and calculate the median only based on the numeric values.\n\nTo calculate the median, the fu...
[ { "content": "Design a JavaScript function named \"calculate\" that calculates the median of a given array. The array can contain both numbers and strings. The function should ignore any non-numeric values in the array and calculate the median only based on the numeric values.\n\nTo calculate the median, the fu...
6
1
[ { "content": "Create a JavaScript function that takes three parameters: a number, a sign, and another number. The function should use the sign to determine which arithmetic operation it should perform and output the result.\n\nHowever, you are not allowed to use any built-in arithmetic operators (+, -, *, /) or...
[ { "content": "Create a JavaScript function that takes three parameters: a number, a sign, and another number. The function should use the sign to determine which arithmetic operation it should perform and output the result.\n\nHowever, you are not allowed to use any built-in arithmetic operators (+, -, *, /) or...
7
2
[ { "content": "Write a JavaScript code snippet that will multiply two numbers, each with up to 10^6 digits. The code should be optimized for performance and memory usage. Additionally, you are not allowed to use any built-in JavaScript libraries or functions for arithmetic operations.\n\nTime Complexity: O(n^2)\...
[ { "content": "Write a JavaScript code snippet that will multiply two numbers, each with up to 10^6 digits. The code should be optimized for performance and memory usage. Additionally, you are not allowed to use any built-in JavaScript libraries or functions for arithmetic operations.\n\nTime Complexity: O(n^2)\...
8
1
[ { "content": "Write a JavaScript program to get the current user's timezone offset from UTC in minutes, using the Date object and without using any built-in methods or libraries. Additionally, you should not use any conditional statements, loops, or arithmetic operators in your solution.", "role": "user" ...
[ { "content": "Write a JavaScript program to get the current user's timezone offset from UTC in minutes, using the Date object and without using any built-in methods or libraries. Additionally, you should not use any conditional statements, loops, or arithmetic operators in your solution.", "role": "user" ...
9
9
[ { "content": "Create a function in JavaScript to input two strings and output their combined length. However, you must implement the function without using the built-in JavaScript functions such as length(), concat(), or any other string manipulation functions. You are only allowed to use basic string operation...
[ { "content": "Create a function in JavaScript to input two strings and output their combined length. However, you must implement the function without using the built-in JavaScript functions such as length(), concat(), or any other string manipulation functions. You are only allowed to use basic string operation...
7
4
[ { "content": "Write a script in JavaScript to find the sum of all the numbers in an array. The array may contain negative numbers as well. The script should not use any built-in array methods such as `reduce` or `forEach` to calculate the sum. The time complexity of the script should be O(n), where n is the len...
[ { "content": "Write a script in JavaScript to find the sum of all the numbers in an array. The array may contain negative numbers as well. The script should not use any built-in array methods such as `reduce` or `forEach` to calculate the sum. The time complexity of the script should be O(n), where n is the len...
9
9
[ { "content": "Create a loop in JavaScript that logs \"Hello, World!\" to the console 15 times. Additionally, after every even iteration, add the current iteration number to the message. However, instead of using a simple for loop or a while loop, you must use a recursive function to calculate the iteration numb...
[ { "content": "Create a loop in JavaScript that logs \"Hello, World!\" to the console 15 times. Additionally, after every even iteration, add the current iteration number to the message. However, instead of using a simple for loop or a while loop, you must use a recursive function to calculate the iteration numb...
8
3
[ { "content": "Develop a JavaScript program to print the average of a given set of numbers. The program should handle cases where the set of numbers may contain negative values. Additionally, the program should only consider numbers that are divisible by 3 in the calculation of the average. The program should al...
[ { "content": "Develop a JavaScript program to print the average of a given set of numbers. The program should handle cases where the set of numbers may contain negative values. Additionally, the program should only consider numbers that are divisible by 3 in the calculation of the average. The program should al...
8
8
[ { "content": "Find the maximum and minimum number in the following array with JavaScript. However, you are not allowed to use the built-in functions `Math.max()` and `Math.min()`. Additionally, you are not allowed to use any loops, recursion, or additional data structures.\n\nProvide a piece of erroneous code a...
[ { "content": "Find the maximum and minimum number in the following array with JavaScript. However, you are not allowed to use the built-in functions `Math.max()` and `Math.min()`. Additionally, you are not allowed to use any loops, recursion, or additional data structures.\n\nProvide a piece of erroneous code a...
7
3
[ { "content": "Create a JavaScript object to store a user's information, where the user's email must be unique among all users in the system. Additionally, implement a method to validate the user's password strength, which should have a minimum length of 15 characters, at least three uppercase letters, three low...
[ { "content": "Create a JavaScript object to store a user's information, where the user's email must be unique among all users in the system. Additionally, implement a method to validate the user's password strength, which should have a minimum length of 15 characters, at least three uppercase letters, three low...
9
3
[ { "content": "Write a JavaScript code snippet to loop through an array of positive integers and return the sum of all the elements that are divisible by a specific prime number. However, you are not allowed to use the modulus operator (%) or any other built-in JavaScript functions to check for divisibility. You...
[ { "content": "Write a JavaScript code snippet to loop through an array of positive integers and return the sum of all the elements that are divisible by a specific prime number. However, you are not allowed to use the modulus operator (%) or any other built-in JavaScript functions to check for divisibility. You...
8
8
[ { "content": "Write a Node.js program to create a load balancer that can handle concurrent requests and supports HTTPS. Implement a load balancing algorithm to distribute incoming requests across multiple server instances. Ensure that the load balancer can handle at least 1000 concurrent requests at any given t...
[ { "content": "Write a Node.js program to create a load balancer that can handle concurrent requests and supports HTTPS. Implement a load balancing algorithm to distribute incoming requests across multiple server instances. Ensure that the load balancer can handle at least 1000 concurrent requests at any given t...
7
2
[ { "content": "Write a JavaScript program to classify a given array of strings into four groups - one which contains elements that can be parsed into integers, one which can be parsed into floating-point numbers, one which can be parsed into hexadecimal numbers, and one which can't be parsed into any of the abov...
[ { "content": "Write a JavaScript program to classify a given array of strings into four groups - one which contains elements that can be parsed into integers, one which can be parsed into floating-point numbers, one which can be parsed into hexadecimal numbers, and one which can't be parsed into any of the abov...
7
4
[ { "content": "Propose a JavaScript function that takes in a string and returns a new string with the characters reversed. The function should have a time complexity of O(n), where n is the length of the input string.\n\nAdditionally, the function should handle special characters, whitespace, and uppercase lette...
[ { "content": "Propose a JavaScript function that takes in a string and returns a new string with the characters reversed. The function should have a time complexity of O(n), where n is the length of the input string.\n\nAdditionally, the function should handle special characters, whitespace, and uppercase lette...
6
6