chosen
listlengths
2
2
rejected
listlengths
2
2
score_chosen
int64
6
9
score_rejected
int64
1
9
[ { "content": "Write a JavaScript program to sort an array of strings according to the length of each string. The program should also handle strings that contain both uppercase and lowercase letters. Additionally, the program should ignore any strings that contain numbers or special characters. Finally, the prog...
[ { "content": "Write a JavaScript program to sort an array of strings according to the length of each string. The program should also handle strings that contain both uppercase and lowercase letters. Additionally, the program should ignore any strings that contain numbers or special characters. Finally, the prog...
8
8
[ { "content": "How can we remove duplicates from an array in JavaScript without using any built-in array methods, additional data structures, or nested loops?", "role": "user" }, { "content": "To remove duplicates from an array in JavaScript without using any built-in array methods, additional data s...
[ { "content": "How can we remove duplicates from an array in JavaScript without using any built-in array methods, additional data structures, or nested loops?", "role": "user" }, { "content": "To remove duplicates from an array in JavaScript without using any built-in array methods, additional data s...
9
9
[ { "content": "Write an AngularJS controller to set the \"page\" variable to be the same as the page parameter passed in the URL, but only if the page parameter is a positive integer greater than 10 and less than 100. Additionally, the controller should validate that the page parameter is provided in the URL and...
[ { "content": "Write an AngularJS controller to set the \"page\" variable to be the same as the page parameter passed in the URL, but only if the page parameter is a positive integer greater than 10 and less than 100. Additionally, the controller should validate that the page parameter is provided in the URL and...
9
9
[ { "content": "Write a JavaScript function to modify a given list and convert all elements to lowercase. The function should not use any built-in JavaScript methods or libraries for string manipulation. Additionally, the function should only use a constant amount of extra space (i.e. no additional data structure...
[ { "content": "Write a JavaScript function to modify a given list and convert all elements to lowercase. The function should not use any built-in JavaScript methods or libraries for string manipulation. Additionally, the function should only use a constant amount of extra space (i.e. no additional data structure...
8
8
[ { "content": "Write a sliding window algorithm in JavaScript to collect all the subarrays with size k from an array of size n. In the resulting subarray, each element should be raised to the power of 3. Return the product of all the subarrays.\n\nlet input = [1, 2, 3, 4, 5, 6, 7, 8];\nlet K = 3;\n\nExample:\nIn...
[ { "content": "Write a sliding window algorithm in JavaScript to collect all the subarrays with size k from an array of size n. In the resulting subarray, each element should be raised to the power of 3. Return the product of all the subarrays.\n\nlet input = [1, 2, 3, 4, 5, 6, 7, 8];\nlet K = 3;\n\nExample:\nIn...
7
3
[ { "content": "Given an array of numbers, write a prototype JavaScript function to find the average value of all numbers in the array. \nIf the array is empty, the function should return 0. If the array contains any non-numeric values or negative numbers, the function should skip those values and calculate the a...
[ { "content": "Given an array of numbers, write a prototype JavaScript function to find the average value of all numbers in the array. \nIf the array is empty, the function should return 0. If the array contains any non-numeric values or negative numbers, the function should skip those values and calculate the a...
6
6
[ { "content": "Explain the concept of serverside rendering in web development, highlighting its advantages and disadvantages. Discuss the importance of server-side rendering in relation to search engine optimization (SEO) and the impact it can have on website performance. Additionally, provide a detailed code ex...
[ { "content": "Explain the concept of serverside rendering in web development, highlighting its advantages and disadvantages. Discuss the importance of server-side rendering in relation to search engine optimization (SEO) and the impact it can have on website performance. Additionally, provide a detailed code ex...
9
9
[ { "content": "Convert the given JavaScript object to an array while excluding the properties that start with the letter 's', the properties whose values are less than 10, and the properties whose values are greater than 100.", "role": "user" }, { "content": "To convert a JavaScript object to an arra...
[ { "content": "Convert the given JavaScript object to an array while excluding the properties that start with the letter 's', the properties whose values are less than 10, and the properties whose values are greater than 100.", "role": "user" }, { "content": "To convert a JavaScript object to an arra...
9
3
[ { "content": "Find the absolute difference between the objects in the following JavaScript code, considering only the values of the numeric properties and excluding any non-numeric properties. The solution should also handle nested objects and arrays, where the absolute difference should be calculated recursive...
[ { "content": "Find the absolute difference between the objects in the following JavaScript code, considering only the values of the numeric properties and excluding any non-numeric properties. The solution should also handle nested objects and arrays, where the absolute difference should be calculated recursive...
6
6
[ { "content": "Construct a regular expression in JavaScript to check if a given string starts with exactly two vowels, followed by one or more consonants, and ends with exactly three consonants.", "role": "user" }, { "content": "The regular expression to check if a given string starts with exactly tw...
[ { "content": "Construct a regular expression in JavaScript to check if a given string starts with exactly two vowels, followed by one or more consonants, and ends with exactly three consonants.", "role": "user" }, { "content": "The regular expression to check if a given string starts with exactly tw...
8
8
[ { "content": "Write a function in JavaScript that takes an array of integers as a parameter and returns a new array where each element is the sum of all the elements in the original array except for the corresponding element. The function should not use any built-in array manipulation methods or functions. The ...
[ { "content": "Write a function in JavaScript that takes an array of integers as a parameter and returns a new array where each element is the sum of all the elements in the original array except for the corresponding element. The function should not use any built-in array manipulation methods or functions. The ...
8
8
[ { "content": "Create a JSON object in JavaScript that stores the data of multiple students, where each student has a name, age, and a list of courses they are enrolled in. The courses should include the name, professor, time slot, and a list of textbooks required for the course. Each student should also have a ...
[ { "content": "Create a JSON object in JavaScript that stores the data of multiple students, where each student has a name, age, and a list of courses they are enrolled in. The courses should include the name, professor, time slot, and a list of textbooks required for the course. Each student should also have a ...
7
7
[ { "content": "Write a JavaScript function to test if two given arrays are equal. The function should also handle nested arrays and return true only if the arrays have the same elements in the same order, while ignoring any additional elements or elements in different positions. Additionally, the function should...
[ { "content": "Write a JavaScript function to test if two given arrays are equal. The function should also handle nested arrays and return true only if the arrays have the same elements in the same order, while ignoring any additional elements or elements in different positions. Additionally, the function should...
6
6
[ { "content": "Add an element to the beginning of an array, but do not use any built-in functions or methods that directly add elements to an array (e.g., push, unshift). You can only modify the array by directly manipulating its memory. The resulting array should be [2, 3, 4, 6, 9]. Additionally, you must ensur...
[ { "content": "Add an element to the beginning of an array, but do not use any built-in functions or methods that directly add elements to an array (e.g., push, unshift). You can only modify the array by directly manipulating its memory. The resulting array should be [2, 3, 4, 6, 9]. Additionally, you must ensur...
6
2
[ { "content": "Write a JavaScript function that takes two arguments: a string representing a color and an array of HTML elements. The function should change the background color of each element in the array to the specified color.\n\nThe function should also check if the color provided is valid. A valid color is...
[ { "content": "Write a JavaScript function that takes two arguments: a string representing a color and an array of HTML elements. The function should change the background color of each element in the array to the specified color.\n\nThe function should also check if the color provided is valid. A valid color is...
7
7
[ { "content": "Modify the following JavaScript code to make it return the absolute value of a given number, without using any built-in JavaScript functions or operators. Additionally, you are not allowed to use any conditional statements (such as if, else, or switch) or loops.\n\nfunction absoluteValue(num) {\n ...
[ { "content": "Modify the following JavaScript code to make it return the absolute value of a given number, without using any built-in JavaScript functions or operators. Additionally, you are not allowed to use any conditional statements (such as if, else, or switch) or loops.\n\nfunction absoluteValue(num) {\n ...
9
9
[ { "content": "Construct an array of 10 random numbers between 1 and 100, without using any built-in JavaScript functions for generating random numbers. Additionally, ensure that none of the generated numbers are duplicates.", "role": "user" }, { "content": "Here is an example of how you can generate...
[ { "content": "Construct an array of 10 random numbers between 1 and 100, without using any built-in JavaScript functions for generating random numbers. Additionally, ensure that none of the generated numbers are duplicates.", "role": "user" }, { "content": "Here is an example of how you can generate...
8
8
[ { "content": "Explain the following piece of JavaScript code. Write a function that takes in two arrays, arr1 and arr2, both containing integers. The function should create a new array, arr3, by combining the elements from arr1 and arr2 in the following order: the first element from arr1, the first element from...
[ { "content": "Explain the following piece of JavaScript code. Write a function that takes in two arrays, arr1 and arr2, both containing integers. The function should create a new array, arr3, by combining the elements from arr1 and arr2 in the following order: the first element from arr1, the first element from...
6
6
[ { "content": "Generate a program in JavaScript to find the longest common substring of two strings, but now the strings can contain special characters, digits, and whitespace in addition to alphabets.\nstr1 = \"a@b 1cd\"\nstr2 = \"cd ef9g\"", "role": "user" }, { "content": "Here's a program in JavaS...
[ { "content": "Generate a program in JavaScript to find the longest common substring of two strings, but now the strings can contain special characters, digits, and whitespace in addition to alphabets.\nstr1 = \"a@b 1cd\"\nstr2 = \"cd ef9g\"", "role": "user" }, { "content": "Here's a program in JavaS...
8
1
[ { "content": "Define a callback in JavaScript to be used with the onclick event. The callback should only execute if the user has clicked the button exactly five times within a 3-second interval and the button is pressed using the right mouse button.", "role": "user" }, { "content": "In JavaScript, ...
[ { "content": "Define a callback in JavaScript to be used with the onclick event. The callback should only execute if the user has clicked the button exactly five times within a 3-second interval and the button is pressed using the right mouse button.", "role": "user" }, { "content": "In JavaScript, ...
8
8
[ { "content": "Develop a function in JavaScript to calculate the volume of a sphere.\nThe function should take the radius of the sphere as a parameter and return the volume.\nThe radius can be a floating-point number.\nThe formula for calculating the volume of a sphere is (4/3) * π * radius^3.\n\nExample:\n\ncal...
[ { "content": "Develop a function in JavaScript to calculate the volume of a sphere.\nThe function should take the radius of the sphere as a parameter and return the volume.\nThe radius can be a floating-point number.\nThe formula for calculating the volume of a sphere is (4/3) * π * radius^3.\n\nExample:\n\ncal...
9
9
[ { "content": "Write a JavaScript function that converts a string to title case, but only for words that are longer than 5 characters. The function should also ignore common words such as \"the\", \"and\", \"or\", \"but\", and \"is\". The converted string should have the first letter of every eligible word capit...
[ { "content": "Write a JavaScript function that converts a string to title case, but only for words that are longer than 5 characters. The function should also ignore common words such as \"the\", \"and\", \"or\", \"but\", and \"is\". The converted string should have the first letter of every eligible word capit...
6
1
[ { "content": "Create an array with the following elements: 1, 2, 3, 2, 1, 4, 5, 4, 3, 2, 1. Write a function that removes all duplicate elements from the array and returns a new array containing only the unique elements. The function should also sort the elements in descending order.", "role": "user" }, ...
[ { "content": "Create an array with the following elements: 1, 2, 3, 2, 1, 4, 5, 4, 3, 2, 1. Write a function that removes all duplicate elements from the array and returns a new array containing only the unique elements. The function should also sort the elements in descending order.", "role": "user" }, ...
6
6
[ { "content": "Write a JavaScript function to validate the syntax of an IP address. Additionally, the function should check if the IP address is within a specific range of valid IP addresses. The range of valid IP addresses should be provided as a parameter to the function. The function should also handle IPv6 a...
[ { "content": "Write a JavaScript function to validate the syntax of an IP address. Additionally, the function should check if the IP address is within a specific range of valid IP addresses. The range of valid IP addresses should be provided as a parameter to the function. The function should also handle IPv6 a...
7
7
[ { "content": "Write a JavaScript code snippet that generates a random password with the following criteria:\n- The password must be 10 characters long.\n- It must contain at least one uppercase letter, one lowercase letter, one digit, and one special character (!@#$%^&*).\n- The password should not contain any ...
[ { "content": "Write a JavaScript code snippet that generates a random password with the following criteria:\n- The password must be 10 characters long.\n- It must contain at least one uppercase letter, one lowercase letter, one digit, and one special character (!@#$%^&*).\n- The password should not contain any ...
7
7
[ { "content": "Create a function in JavaScript called \"printHello\" that takes in a number parameter \"n\". The function should print \"Hello\" n times using a for loop. However, the function should print \"Hello\" in reverse order from n to 1. If n is not a positive integer, the function should return an error...
[ { "content": "Create a function in JavaScript called \"printHello\" that takes in a number parameter \"n\". The function should print \"Hello\" n times using a for loop. However, the function should print \"Hello\" in reverse order from n to 1. If n is not a positive integer, the function should return an error...
8
8
[ { "content": "Create a JavaScript program to find the minimum of three numbers, but the numbers must be stored in an array and the program must use recursion to find the minimum.", "role": "user" }, { "content": "Here's a JavaScript program that uses recursion to find the minimum of three numbers st...
[ { "content": "Create a JavaScript program to find the minimum of three numbers, but the numbers must be stored in an array and the program must use recursion to find the minimum.", "role": "user" }, { "content": "Here's a JavaScript program that uses recursion to find the minimum of three numbers st...
9
4
[ { "content": "Write a JavaScript function that takes in a string representing a sentence and returns an array of the most common words in the sentence, excluding common stop words. The function should also exclude any words that are less than 3 characters long. The function should return the words in descending...
[ { "content": "Write a JavaScript function that takes in a string representing a sentence and returns an array of the most common words in the sentence, excluding common stop words. The function should also exclude any words that are less than 3 characters long. The function should return the words in descending...
7
7
[ { "content": "Create a JavaScript program that generates the Fibonacci sequence up to a given number provided by the user. The program should print out the Fibonacci sequence in reverse order and also calculate the sum of all the numbers in the sequence. Additionally, the program should implement a recursive fu...
[ { "content": "Create a JavaScript program that generates the Fibonacci sequence up to a given number provided by the user. The program should print out the Fibonacci sequence in reverse order and also calculate the sum of all the numbers in the sequence. Additionally, the program should implement a recursive fu...
6
6
[ { "content": "Create a function in JavaScript which prints all twin prime numbers up to a given number.\n\n(Note: Twin prime numbers are a pair of prime numbers that differ by 2, for example, (3, 5), (11, 13), (17, 19), etc.)\n\nAdditionally, make sure to implement the function using a recursive approach rather...
[ { "content": "Create a function in JavaScript which prints all twin prime numbers up to a given number.\n\n(Note: Twin prime numbers are a pair of prime numbers that differ by 2, for example, (3, 5), (11, 13), (17, 19), etc.)\n\nAdditionally, make sure to implement the function using a recursive approach rather...
6
6
[ { "content": "Create a JavaScript function that takes a string as an argument, reverses it, and removes all duplicate characters, returning the result. The input string will only contain lowercase letters and have a maximum length of 100 characters. Additionally, the function should ignore any vowels in the inp...
[ { "content": "Create a JavaScript function that takes a string as an argument, reverses it, and removes all duplicate characters, returning the result. The input string will only contain lowercase letters and have a maximum length of 100 characters. Additionally, the function should ignore any vowels in the inp...
6
6
[ { "content": "Sort the following array of numbers [7,2,4,1,9] in descending order using JavaScript. \nAdditional requirements: \n- You are not allowed to use any built-in sorting functions or libraries.\n- You must implement your own sorting algorithm.\n- Your sorting algorithm should have a time complexity of ...
[ { "content": "Sort the following array of numbers [7,2,4,1,9] in descending order using JavaScript. \nAdditional requirements: \n- You are not allowed to use any built-in sorting functions or libraries.\n- You must implement your own sorting algorithm.\n- Your sorting algorithm should have a time complexity of ...
8
8
[ { "content": "Create a RESTful API in Node.js that returns the Fibonacci sequence up to a given number when it is invoked. The API should accept a positive integer as a parameter and return a JSON response containing the Fibonacci sequence up to that number. Additionally, the API should implement rate limiting,...
[ { "content": "Create a RESTful API in Node.js that returns the Fibonacci sequence up to a given number when it is invoked. The API should accept a positive integer as a parameter and return a JSON response containing the Fibonacci sequence up to that number. Additionally, the API should implement rate limiting,...
7
7
[ { "content": "Write a JavaScript function to calculate the length of a given string without using the built-in `length` property or any other string manipulation methods, and with a time complexity of O(n).", "role": "user" }, { "content": "Here's a JavaScript function that calculates the length of ...
[ { "content": "Write a JavaScript function to calculate the length of a given string without using the built-in `length` property or any other string manipulation methods, and with a time complexity of O(n).", "role": "user" }, { "content": "Here's a JavaScript function that calculates the length of ...
9
9
[ { "content": "Create a web page using HTML, CSS, and JavaScript that contains a heading, a button, and a form. When the button is clicked, the form should be validated to check if all required fields are filled out. If any required fields are empty, display an error message next to each empty field. Additionall...
[ { "content": "Create a web page using HTML, CSS, and JavaScript that contains a heading, a button, and a form. When the button is clicked, the form should be validated to check if all required fields are filled out. If any required fields are empty, display an error message next to each empty field. Additionall...
6
4
[ { "content": "Write a function in JavaScript to set the background color of a web page to a randomly generated color, but the generated color should be a shade of blue. The shade of blue should have a hue value between 180 and 240, a saturation value between 50% and 100%, and a lightness value between 20% and 8...
[ { "content": "Write a function in JavaScript to set the background color of a web page to a randomly generated color, but the generated color should be a shade of blue. The shade of blue should have a hue value between 180 and 240, a saturation value between 50% and 100%, and a lightness value between 20% and 8...
9
9
[ { "content": "Provide the JavaScript code required to navigate to a page when the page is loaded, but the URL of the page to navigate to should be determined dynamically based on the user's input. Additionally, the code should include error handling to display an error message if the user's input is invalid or ...
[ { "content": "Provide the JavaScript code required to navigate to a page when the page is loaded, but the URL of the page to navigate to should be determined dynamically based on the user's input. Additionally, the code should include error handling to display an error message if the user's input is invalid or ...
7
3
[ { "content": "Write a JavaScript program to find all the words in a string which start with a specific letter and are followed by a vowel, and are not preceded or followed by any punctuation or whitespace characters. Consider handling cases where the specific letter can be either lowercase or uppercase.", "...
[ { "content": "Write a JavaScript program to find all the words in a string which start with a specific letter and are followed by a vowel, and are not preceded or followed by any punctuation or whitespace characters. Consider handling cases where the specific letter can be either lowercase or uppercase.", "...
8
8
[ { "content": "Write a JavaScript program to make a deep clone of an object, ensuring that all properties of the cloned object are in uppercase, sorted in descending order, and any nested objects are also deeply cloned.", "role": "user" }, { "content": "Here's a JavaScript program that deep clones an...
[ { "content": "Write a JavaScript program to make a deep clone of an object, ensuring that all properties of the cloned object are in uppercase, sorted in descending order, and any nested objects are also deeply cloned.", "role": "user" }, { "content": "Here's a JavaScript program that deep clones an...
6
6
[ { "content": "Create a method in JavaScript that will return the area of a triangle, but without using any built-in mathematical functions or operators for multiplication, division, or exponentiation.", "role": "user" }, { "content": "Here's a JavaScript method that calculates the area of a triangle...
[ { "content": "Create a method in JavaScript that will return the area of a triangle, but without using any built-in mathematical functions or operators for multiplication, division, or exponentiation.", "role": "user" }, { "content": "Here's a JavaScript method that calculates the area of a triangle...
6
6
[ { "content": "Write a search engine using an index in JavaScript. The search engine should be able to handle large amounts of data efficiently, with a time complexity of O(log n) for search operations. Additionally, implement a feature that suggests related search terms based on the user's input, with a space c...
[ { "content": "Write a search engine using an index in JavaScript. The search engine should be able to handle large amounts of data efficiently, with a time complexity of O(log n) for search operations. Additionally, implement a feature that suggests related search terms based on the user's input, with a space c...
7
7
[ { "content": "Create a function in JavaScript to generate an array containing 10 unique prime random numbers between 1 and 1000 (inclusive) in descending order.", "role": "user" }, { "content": "Here's a function in JavaScript that generates an array containing 10 unique prime random numbers between...
[ { "content": "Create a function in JavaScript to generate an array containing 10 unique prime random numbers between 1 and 1000 (inclusive) in descending order.", "role": "user" }, { "content": "Here's a function in JavaScript that generates an array containing 10 unique prime random numbers between...
8
3
[ { "content": "Create a JavaScript object that contains a student's name, age, courses, and grades for each course. The object should also include a method to calculate the student's average grade. The time complexity of calculating the average grade should be O(1), regardless of the number of courses the studen...
[ { "content": "Create a JavaScript object that contains a student's name, age, courses, and grades for each course. The object should also include a method to calculate the student's average grade. The time complexity of calculating the average grade should be O(1), regardless of the number of courses the studen...
7
7
[ { "content": "Write a JavaScript function that generates the Fibonacci sequence up to a given number, while also calculating the sum of all the numbers in the sequence. Additionally, modify the function to accept multiple arguments, where each argument represents a limit for a separate Fibonacci sequence. The f...
[ { "content": "Write a JavaScript function that generates the Fibonacci sequence up to a given number, while also calculating the sum of all the numbers in the sequence. Additionally, modify the function to accept multiple arguments, where each argument represents a limit for a separate Fibonacci sequence. The f...
7
7
[ { "content": "Write a jQuery script which animates an element from left to right with a duration of 2 seconds and a delay of 500 milliseconds before starting the animation.\nThe animation should only start when the element is clicked and the animation should only be triggered if the window width is greater than...
[ { "content": "Write a jQuery script which animates an element from left to right with a duration of 2 seconds and a delay of 500 milliseconds before starting the animation.\nThe animation should only start when the element is clicked and the animation should only be triggered if the window width is greater than...
7
4
[ { "content": "Create a React component that will render a list of student details for a particular class. The component should also include a search functionality that allows the user to filter the list based on specific criteria such as student name, grade, or attendance. Additionally, the component should dis...
[ { "content": "Create a React component that will render a list of student details for a particular class. The component should also include a search functionality that allows the user to filter the list based on specific criteria such as student name, grade, or attendance. Additionally, the component should dis...
9
3
[ { "content": "Create a function in JavaScript that implements the bubble sort algorithm to sort an array of objects. The objects have the following properties: \"name\" (string), \"age\" (number), and \"score\" (number).\n\nThe function should sort the array of objects based on the following criteria:\n\n1. Sor...
[ { "content": "Create a function in JavaScript that implements the bubble sort algorithm to sort an array of objects. The objects have the following properties: \"name\" (string), \"age\" (number), and \"score\" (number).\n\nThe function should sort the array of objects based on the following criteria:\n\n1. Sor...
9
1
[ { "content": "Create a React component that renders the current date and time in the format \"YYYY-MM-DD HH:MM:SS\" and displays it as a countdown timer, starting from a specified end date and time. The component should update in real-time, ticking down every second until it reaches the end time.\n\n#Erroneous ...
[ { "content": "Create a React component that renders the current date and time in the format \"YYYY-MM-DD HH:MM:SS\" and displays it as a countdown timer, starting from a specified end date and time. The component should update in real-time, ticking down every second until it reaches the end time.\n\n#Erroneous ...
7
7
[ { "content": "Using the code provided, write a JavaScript function that checks if a given number is prime or not. However, you must implement the function without using any looping constructs (such as for, while, or do-while). Additionally, the function must have a time complexity of O(sqrt(n)), where n is the ...
[ { "content": "Using the code provided, write a JavaScript function that checks if a given number is prime or not. However, you must implement the function without using any looping constructs (such as for, while, or do-while). Additionally, the function must have a time complexity of O(sqrt(n)), where n is the ...
7
3
[ { "content": "Edit the following array in JavaScript so that all the strings are in uppercase. However, instead of using the built-in `toUpperCase()` method, you need to implement your own function to convert each string to uppercase. You are not allowed to use any built-in string manipulation functions.\n\nIn ...
[ { "content": "Edit the following array in JavaScript so that all the strings are in uppercase. However, instead of using the built-in `toUpperCase()` method, you need to implement your own function to convert each string to uppercase. You are not allowed to use any built-in string manipulation functions.\n\nIn ...
6
6
[ { "content": "Rewritten Test:\nWrite a JavaScript program that prompts the user to enter their name and then prints \"Hello, [name]\" to the console. The program should also calculate the length of the entered name and display it along with the greeting.\n\nIn addition, modify the program to check if the user h...
[ { "content": "Rewritten Test:\nWrite a JavaScript program that prompts the user to enter their name and then prints \"Hello, [name]\" to the console. The program should also calculate the length of the entered name and display it along with the greeting.\n\nIn addition, modify the program to check if the user h...
8
8
[ { "content": "Create a JavaScript function to generate a random number between a user-entered minimum and maximum values. The function should also include error handling for cases where the user enters invalid inputs. The function should only use a maximum of three lines of code and should not use any built-in ...
[ { "content": "Create a JavaScript function to generate a random number between a user-entered minimum and maximum values. The function should also include error handling for cases where the user enters invalid inputs. The function should only use a maximum of three lines of code and should not use any built-in ...
9
9
[ { "content": "Write a JavaScript function that takes two parameters, which are both arrays of numbers, and compares them. The function should return true if the sum of the numbers in the first array is greater than the sum of the numbers in the second array, false if the sums are equal, and \"undefined\" if the...
[ { "content": "Write a JavaScript function that takes two parameters, which are both arrays of numbers, and compares them. The function should return true if the sum of the numbers in the first array is greater than the sum of the numbers in the second array, false if the sums are equal, and \"undefined\" if the...
7
7
[ { "content": "Suppose you have an array of numbers like [2,5,3,7] and you have to find the sum of all the positive elements of the array. Write a JavaScript program for this.\n\nPlease note that the array may contain negative numbers as well.\n\n## Additional Requirements:\n1. Your program should handle an empt...
[ { "content": "Suppose you have an array of numbers like [2,5,3,7] and you have to find the sum of all the positive elements of the array. Write a JavaScript program for this.\n\nPlease note that the array may contain negative numbers as well.\n\n## Additional Requirements:\n1. Your program should handle an empt...
6
4
[ { "content": "Write a JavaScript program to simulate a rock, paper, scissors game between 5 players. Each player should make their choice (rock, paper, or scissors) and the program should determine the winner based on the rules of the game.\n\nAdditionally, implement a scoring system that keeps track of the tot...
[ { "content": "Write a JavaScript program to simulate a rock, paper, scissors game between 5 players. Each player should make their choice (rock, paper, or scissors) and the program should determine the winner based on the rules of the game.\n\nAdditionally, implement a scoring system that keeps track of the tot...
8
8
[ { "content": "Construct an array of unique prime integers from 1 to 10000 in ascending order using Javascript.", "role": "user" }, { "content": "Here is a possible implementation using the Sieve of Eratosthenes algorithm in JavaScript:\n\n```javascript\nfunction findPrimes(limit) {\n // Create an a...
[ { "content": "Construct an array of unique prime integers from 1 to 10000 in ascending order using Javascript.", "role": "user" }, { "content": "Here is a possible implementation using the Sieve of Eratosthenes algorithm in JavaScript:\n\n```javascript\nfunction findPrimes(limit) {\n // Create an a...
8
8
[ { "content": "Write a recursive function in JavaScript that reverses a given string, but without using any built-in string manipulation methods or additional data structures.\n\nExample:\nInput: \"Hello, world!\"\nOutput: \"!dlrow ,olleH\"\n\nYou can assume that the input string will only contain alphanumeric c...
[ { "content": "Write a recursive function in JavaScript that reverses a given string, but without using any built-in string manipulation methods or additional data structures.\n\nExample:\nInput: \"Hello, world!\"\nOutput: \"!dlrow ,olleH\"\n\nYou can assume that the input string will only contain alphanumeric c...
8
2
[ { "content": "Develop a custom API endpoint for an online store using Node.js that allows users to add items to their shopping cart. Each item should have a name, price, and quantity. \n\nThe endpoint should validate that the user is logged in before adding an item to the cart. If the user is not logged in, an ...
[ { "content": "Develop a custom API endpoint for an online store using Node.js that allows users to add items to their shopping cart. Each item should have a name, price, and quantity. \n\nThe endpoint should validate that the user is logged in before adding an item to the cart. If the user is not logged in, an ...
7
7
[ { "content": "Create a program in JavaScript that calendarizes the upcoming week based on the current date. Additionally, the program should implement a feature that allows the user to input their preferred start day of the week (e.g., Sunday, Monday, etc.) and display the calendar accordingly. The program shou...
[ { "content": "Create a program in JavaScript that calendarizes the upcoming week based on the current date. Additionally, the program should implement a feature that allows the user to input their preferred start day of the week (e.g., Sunday, Monday, etc.) and display the calendar accordingly. The program shou...
9
2
[ { "content": "Given a string, write code to reverse it in JavaScript.\n\nString: \"programming\"\n\nTime Complexity: O(n)\n\nSpace Complexity: O(1)\n\nYou are not allowed to use any built-in JavaScript methods or additional data structures.\n\nProvide a piece of erroneous code as a reference to increase misdire...
[ { "content": "Given a string, write code to reverse it in JavaScript.\n\nString: \"programming\"\n\nTime Complexity: O(n)\n\nSpace Complexity: O(1)\n\nYou are not allowed to use any built-in JavaScript methods or additional data structures.\n\nProvide a piece of erroneous code as a reference to increase misdire...
7
3
[ { "content": "Explain the difference between post(), put(), and delete() in AJAX, and provide examples of when each method should be used. Additionally, discuss the benefits and drawbacks of using each method in different scenarios.", "role": "user" }, { "content": "In AJAX, the post(), put(), and d...
[ { "content": "Explain the difference between post(), put(), and delete() in AJAX, and provide examples of when each method should be used. Additionally, discuss the benefits and drawbacks of using each method in different scenarios.", "role": "user" }, { "content": "In AJAX, the post(), put(), and d...
6
6
[ { "content": "Implement a function in JavaScript that finds the second largest element in an array of integers. The function should return the second largest element or -1 if there is no second largest element. The function should have a time complexity of O(n) and a space complexity of O(1).\n\nProvide a piece...
[ { "content": "Implement a function in JavaScript that finds the second largest element in an array of integers. The function should return the second largest element or -1 if there is no second largest element. The function should have a time complexity of O(n) and a space complexity of O(1).\n\nProvide a piece...
6
6
[ { "content": "Write a JavaScript function that checks if the user's age is above 18 and the name is not empty. If both conditions are true, the function should return the name with the first letter capitalized and any leading or trailing whitespace removed. If the name is not provided or is not a string, the fu...
[ { "content": "Write a JavaScript function that checks if the user's age is above 18 and the name is not empty. If both conditions are true, the function should return the name with the first letter capitalized and any leading or trailing whitespace removed. If the name is not provided or is not a string, the fu...
8
8
[ { "content": "How can we obfuscate a JavaScript code to make it harder for hackers to reverse engineer it while ensuring that the performance of the code is not compromised? Provide an example of a commonly used obfuscation technique and explain its benefits and drawbacks.", "role": "user" }, { "con...
[ { "content": "How can we obfuscate a JavaScript code to make it harder for hackers to reverse engineer it while ensuring that the performance of the code is not compromised? Provide an example of a commonly used obfuscation technique and explain its benefits and drawbacks.", "role": "user" }, { "con...
9
1
[ { "content": "Write a JavaScript program to find the sum of all prime numbers between two user-entered integers.", "role": "user" }, { "content": "Here is a JavaScript program that prompts the user to enter two integers and then finds the sum of all prime numbers between those two integers:\n\n```ja...
[ { "content": "Write a JavaScript program to find the sum of all prime numbers between two user-entered integers.", "role": "user" }, { "content": "Here is a JavaScript program that prompts the user to enter two integers and then finds the sum of all prime numbers between those two integers:\n\n```ja...
6
3
[ { "content": "Write a JavaScript function that takes a date as input and returns the corresponding day of the week along with the current time in DD/MM/YYYY hh:mm:ss format. The input date should be in the format YYYY-MM-DD and should be a valid date between 2000-01-01 and 2099-12-31. Additionally, the function...
[ { "content": "Write a JavaScript function that takes a date as input and returns the corresponding day of the week along with the current time in DD/MM/YYYY hh:mm:ss format. The input date should be in the format YYYY-MM-DD and should be a valid date between 2000-01-01 and 2099-12-31. Additionally, the function...
6
6
[ { "content": "Find the maximum number from an array of numbers using JavaScript. The array can contain positive and negative numbers. Implement a solution with a time complexity of O(n), where n is the length of the array. However, you are not allowed to use any built-in JavaScript functions such as Math.max() ...
[ { "content": "Find the maximum number from an array of numbers using JavaScript. The array can contain positive and negative numbers. Implement a solution with a time complexity of O(n), where n is the length of the array. However, you are not allowed to use any built-in JavaScript functions such as Math.max() ...
6
6
[ { "content": "Using JavaScript, create a program that prompts the user to enter the number of unique sites they have visited today. Then, prompt the user to enter the name of each unique site visited. Finally, print the names of the unique sites visited today on the web console in reverse alphabetical order, wi...
[ { "content": "Using JavaScript, create a program that prompts the user to enter the number of unique sites they have visited today. Then, prompt the user to enter the name of each unique site visited. Finally, print the names of the unique sites visited today on the web console in reverse alphabetical order, wi...
8
8
[ { "content": "Design a method in JavaScript to validate a password according to the following criteria:\n1. The password must contain at least 10 characters.\n2. The password must contain at least two uppercase letters.\n3. The password must contain at least two lowercase letters.\n4. The password must contain ...
[ { "content": "Design a method in JavaScript to validate a password according to the following criteria:\n1. The password must contain at least 10 characters.\n2. The password must contain at least two uppercase letters.\n3. The password must contain at least two lowercase letters.\n4. The password must contain ...
8
8
[ { "content": "Write a JavaScript function that takes in a string of HTML code and adds a padding of 10px to all paragraph tags within the code. The function should also add a margin of 5px to all div tags and a background color of #f1f1f1 to all span tags. The modified HTML code should be returned by the functi...
[ { "content": "Write a JavaScript function that takes in a string of HTML code and adds a padding of 10px to all paragraph tags within the code. The function should also add a margin of 5px to all div tags and a background color of #f1f1f1 to all span tags. The modified HTML code should be returned by the functi...
6
6
[ { "content": "Write a JavaScript function to find the maximum value from an array of numbers, but without using the built-in Math.max() method or the spread operator (...). You should iterate through the array and compare each element with the current maximum value found so far, updating the maximum value if ne...
[ { "content": "Write a JavaScript function to find the maximum value from an array of numbers, but without using the built-in Math.max() method or the spread operator (...). You should iterate through the array and compare each element with the current maximum value found so far, updating the maximum value if ne...
8
3
[ { "content": "Construct a JavaScript algorithm to determine whether a number is prime or not, using a recursive approach and without using any built-in mathematical functions or libraries.\nnoinput", "role": "user" }, { "content": "Here is a JavaScript algorithm to determine whether a number is prim...
[ { "content": "Construct a JavaScript algorithm to determine whether a number is prime or not, using a recursive approach and without using any built-in mathematical functions or libraries.\nnoinput", "role": "user" }, { "content": "Here is a JavaScript algorithm to determine whether a number is prim...
6
6
[ { "content": "Write a function in JavaScript that takes in an array of numbers and returns the average of all the elements in the array. The array can contain positive and negative integers, decimal numbers, and empty elements. If the array is empty, the function should return 0.\n\nYou are required to write th...
[ { "content": "Write a function in JavaScript that takes in an array of numbers and returns the average of all the elements in the array. The array can contain positive and negative integers, decimal numbers, and empty elements. If the array is empty, the function should return 0.\n\nYou are required to write th...
7
7
[ { "content": "Create an API endpoint that takes three inputs (phone number, name, and email) and updates contact details in the database.\n\nThe API endpoint should perform the following steps:\n1. Validate the phone number input to ensure it is a valid phone number format (e.g. \"+1 123-456-7890\"). Additional...
[ { "content": "Create an API endpoint that takes three inputs (phone number, name, and email) and updates contact details in the database.\n\nThe API endpoint should perform the following steps:\n1. Validate the phone number input to ensure it is a valid phone number format (e.g. \"+1 123-456-7890\"). Additional...
8
8
[ { "content": "Write a JavaScript function that takes an optional parameter, \"domain\", and deletes all cookies for that domain. The function should have a time complexity of O(n), where n is the number of cookies to be deleted. Additionally, the function should only delete cookies with a specific expiration da...
[ { "content": "Write a JavaScript function that takes an optional parameter, \"domain\", and deletes all cookies for that domain. The function should have a time complexity of O(n), where n is the number of cookies to be deleted. Additionally, the function should only delete cookies with a specific expiration da...
6
6
[ { "content": "Write a Javascript code to remove all duplicate values from an array, arr, without using any built-in array methods or data structures. The input array will only contain positive integers. Additionally, the code should be optimized to have a time complexity of O(n) and a space complexity of O(1), ...
[ { "content": "Write a Javascript code to remove all duplicate values from an array, arr, without using any built-in array methods or data structures. The input array will only contain positive integers. Additionally, the code should be optimized to have a time complexity of O(n) and a space complexity of O(1), ...
6
6
[ { "content": "Identify and delete duplicate elements from an array in JavaScript. The array can contain both numbers and strings. The function should return a new array without any duplicate elements, maintaining the order of the elements.\n\nThe time complexity should not exceed O(n^2) and the space complexity...
[ { "content": "Identify and delete duplicate elements from an array in JavaScript. The array can contain both numbers and strings. The function should return a new array without any duplicate elements, maintaining the order of the elements.\n\nThe time complexity should not exceed O(n^2) and the space complexity...
9
2
[ { "content": "How to create a new array from an existing array in JavaScript while filtering out all the elements that are divisible by 2 and then sorting the remaining elements in descending order? Additionally, you must implement the solution using recursion and ensure that the original array is not modified....
[ { "content": "How to create a new array from an existing array in JavaScript while filtering out all the elements that are divisible by 2 and then sorting the remaining elements in descending order? Additionally, you must implement the solution using recursion and ensure that the original array is not modified....
9
9
[ { "content": "What is the purpose of the keyword `break` in a JavaScript loop and provide an example code snippet where `break` is used to terminate the loop before it completes all iterations? Additionally, in the provided code snippet, ensure that the loop iterates over an array of numbers and terminates when...
[ { "content": "What is the purpose of the keyword `break` in a JavaScript loop and provide an example code snippet where `break` is used to terminate the loop before it completes all iterations? Additionally, in the provided code snippet, ensure that the loop iterates over an array of numbers and terminates when...
7
2
[ { "content": "Given an array of numbers, how would you filter the numbers that are divisible by 3 and sort them in descending order. Additionally, you must remove any duplicate numbers from the resulting array and return the first 5 numbers.", "role": "user" }, { "content": "To filter the numbers th...
[ { "content": "Given an array of numbers, how would you filter the numbers that are divisible by 3 and sort them in descending order. Additionally, you must remove any duplicate numbers from the resulting array and return the first 5 numbers.", "role": "user" }, { "content": "To filter the numbers th...
8
8
[ { "content": "Write a JavaScript function to determine if an array is sorted in non-decreasing order or not. The array may contain positive and negative integers.\n\nThe function should have a time complexity of O(n), where n is the length of the array.\n\nYou are not allowed to use any built-in sorting functio...
[ { "content": "Write a JavaScript function to determine if an array is sorted in non-decreasing order or not. The array may contain positive and negative integers.\n\nThe function should have a time complexity of O(n), where n is the length of the array.\n\nYou are not allowed to use any built-in sorting functio...
7
7
[ { "content": "Construct a MongoDB query to sort all documents based on the price in the collection, while ignoring any null or missing price values. Additionally, implement pagination to limit the number of returned documents to 10 per page and include a feature to retrieve a specific page number.", "role":...
[ { "content": "Construct a MongoDB query to sort all documents based on the price in the collection, while ignoring any null or missing price values. Additionally, implement pagination to limit the number of returned documents to 10 per page and include a feature to retrieve a specific page number.", "role":...
7
3
[ { "content": "What is dependency injection and how can it be implemented with JavaScript? Provide code examples and explain the benefits and drawbacks of using dependency injection in JavaScript.\n\nAdditionally, provide a code example that demonstrates a common mistake made when implementing dependency injecti...
[ { "content": "What is dependency injection and how can it be implemented with JavaScript? Provide code examples and explain the benefits and drawbacks of using dependency injection in JavaScript.\n\nAdditionally, provide a code example that demonstrates a common mistake made when implementing dependency injecti...
7
7
[ { "content": "Transform an input string to its uppercase equivalent with JavaScript without using built-in string methods such as `toUpperCase()` or regular expressions. The function should have a time complexity of O(n) and a space complexity of O(1). The input string will contain alphanumeric characters and p...
[ { "content": "Transform an input string to its uppercase equivalent with JavaScript without using built-in string methods such as `toUpperCase()` or regular expressions. The function should have a time complexity of O(n) and a space complexity of O(1). The input string will contain alphanumeric characters and p...
7
7
[ { "content": "Create a JavaScript object to store 10 birds names and their corresponding scientific names. However, ensure that the scientific names are encrypted using a Caesar cipher with a shift of 5.", "role": "user" }, { "content": "Here's a JavaScript object that stores 10 bird names and their...
[ { "content": "Create a JavaScript object to store 10 birds names and their corresponding scientific names. However, ensure that the scientific names are encrypted using a Caesar cipher with a shift of 5.", "role": "user" }, { "content": "Here's a JavaScript object that stores 10 bird names and their...
6
6
[ { "content": "You are tasked with creating a React component that renders a list of 100 divs. Each div should have a unique ID and the ability to be individually clicked and manipulated. Additionally, implement a sorting functionality that allows the user to dynamically rearrange the order of the divs based on ...
[ { "content": "You are tasked with creating a React component that renders a list of 100 divs. Each div should have a unique ID and the ability to be individually clicked and manipulated. Additionally, implement a sorting functionality that allows the user to dynamically rearrange the order of the divs based on ...
6
2
[ { "content": "Create a Node.js server that responds with \"Hello World!\" when the URL \"/hello\" is accessed. Additionally, the server should return a status code of 200 and the response body should include the current date and time in the format \"YYYY-MM-DD HH:MM:SS\". The server should also log the IP addre...
[ { "content": "Create a Node.js server that responds with \"Hello World!\" when the URL \"/hello\" is accessed. Additionally, the server should return a status code of 200 and the response body should include the current date and time in the format \"YYYY-MM-DD HH:MM:SS\". The server should also log the IP addre...
9
4
[ { "content": "Implement a function in JavaScript which checks whether a given number is prime or not. The function should only use a maximum of O(sqrt(n)) time complexity and should not use any built-in prime-checking functions or libraries. The function should handle both positive and negative integers as inpu...
[ { "content": "Implement a function in JavaScript which checks whether a given number is prime or not. The function should only use a maximum of O(sqrt(n)) time complexity and should not use any built-in prime-checking functions or libraries. The function should handle both positive and negative integers as inpu...
9
1
[ { "content": "Write a query to find users who have at least one friend who is exactly 2 years older than them in MongoDB.", "role": "user" }, { "content": "To find users who have at least one friend who is exactly 2 years older than them in MongoDB, you can use the following query:\n\n```javascript\...
[ { "content": "Write a query to find users who have at least one friend who is exactly 2 years older than them in MongoDB.", "role": "user" }, { "content": "To find users who have at least one friend who is exactly 2 years older than them in MongoDB, you can use the following query:\n\n```javascript\...
7
7
[ { "content": "How can we replace multiple occurrences of a substring in a given string with another substring in JavaScript? Provide the correct code snippet to achieve this. Your solution should have a time complexity of O(n) where n is the length of the string. Additionally, you are not allowed to use any bui...
[ { "content": "How can we replace multiple occurrences of a substring in a given string with another substring in JavaScript? Provide the correct code snippet to achieve this. Your solution should have a time complexity of O(n) where n is the length of the string. Additionally, you are not allowed to use any bui...
9
4
[ { "content": "Create a JavaScript function which takes in an array of numbers and returns the second largest number. The function should also check if the array contains duplicate numbers and return an error message if so. Additionally, the function should only use a single loop for both finding the second larg...
[ { "content": "Create a JavaScript function which takes in an array of numbers and returns the second largest number. The function should also check if the array contains duplicate numbers and return an error message if so. Additionally, the function should only use a single loop for both finding the second larg...
7
7
[ { "content": "Write a script to launch a web server listening on port 8080, but the web server should only accept incoming requests from a specific IP address range and restrict access to only clients that have a specific user agent string in their HTTP headers.", "role": "user" }, { "content": "Sur...
[ { "content": "Write a script to launch a web server listening on port 8080, but the web server should only accept incoming requests from a specific IP address range and restrict access to only clients that have a specific user agent string in their HTTP headers.", "role": "user" }, { "content": "Sur...
7
4
[ { "content": "EDIT this JavaScript function to return a list of the square roots of all numbers in a given input array. \nHowever, the solution should have a time complexity of O(n) and should not use any built-in functions or methods that directly calculate square roots. Additionally, the solution should only ...
[ { "content": "EDIT this JavaScript function to return a list of the square roots of all numbers in a given input array. \nHowever, the solution should have a time complexity of O(n) and should not use any built-in functions or methods that directly calculate square roots. Additionally, the solution should only ...
6
6
[ { "content": "Create a JavaScript class to find the difference of two given dates, taking into consideration leap years, timezones, and daylight saving time changes. Additionally, the class should handle dates in different formats, such as ISO 8601, Unix timestamp, and custom string formats. The class should al...
[ { "content": "Create a JavaScript class to find the difference of two given dates, taking into consideration leap years, timezones, and daylight saving time changes. Additionally, the class should handle dates in different formats, such as ISO 8601, Unix timestamp, and custom string formats. The class should al...
8
2
[ { "content": "Write a JavaScript program to filter out prime numbers from an array [1,2,3,4,5,6,7,8,9,10]. Additionally, create a function that determines whether a given number is prime or not, using a nested loop to check for factors.", "role": "user" }, { "content": "Here's a JavaScript program t...
[ { "content": "Write a JavaScript program to filter out prime numbers from an array [1,2,3,4,5,6,7,8,9,10]. Additionally, create a function that determines whether a given number is prime or not, using a nested loop to check for factors.", "role": "user" }, { "content": "Here's a JavaScript program t...
7
7
[ { "content": "Write a JavaScript function that takes in a string as a parameter and logs each character of the string in reverse order in the console. The function should also remove any duplicate characters in the reversed string before logging them.", "role": "user" }, { "content": "Here is a Java...
[ { "content": "Write a JavaScript function that takes in a string as a parameter and logs each character of the string in reverse order in the console. The function should also remove any duplicate characters in the reversed string before logging them.", "role": "user" }, { "content": "Here is a Java...
8
8
[ { "content": "Implement a logic to separate prime and non-prime numbers from an array in JavaScript. The array must contain at least 15 elements. The output should be two separate arrays, one containing prime numbers and the other containing non-prime numbers. The prime numbers array should be sorted in descend...
[ { "content": "Implement a logic to separate prime and non-prime numbers from an array in JavaScript. The array must contain at least 15 elements. The output should be two separate arrays, one containing prime numbers and the other containing non-prime numbers. The prime numbers array should be sorted in descend...
6
6
[ { "content": "Create a JavaScript program to check if a string has at least one uppercase alphabet, one lowercase alphabet, one numeric character, and one special character.", "role": "user" }, { "content": "Here's a JavaScript program that checks if a string contains at least one uppercase alphabet...
[ { "content": "Create a JavaScript program to check if a string has at least one uppercase alphabet, one lowercase alphabet, one numeric character, and one special character.", "role": "user" }, { "content": "Here's a JavaScript program that checks if a string contains at least one uppercase alphabet...
9
9
[ { "content": "Generate a JavaScript function to perform a binary search for a given array, but with the additional requirement that the array must be sorted in descending order and must contain only unique elements.", "role": "user" }, { "content": "Here's a JavaScript function that performs a binar...
[ { "content": "Generate a JavaScript function to perform a binary search for a given array, but with the additional requirement that the array must be sorted in descending order and must contain only unique elements.", "role": "user" }, { "content": "Here's a JavaScript function that performs a binar...
9
4
[ { "content": "Create a JavaScript function to return the sum of the digits in a given number, but without using any built-in string or number manipulation methods (such as toString(), split(), parseInt(), etc.), and with a time complexity of O(log n), where n is the given number.\n\n#Explanation#\nThis rewritte...
[ { "content": "Create a JavaScript function to return the sum of the digits in a given number, but without using any built-in string or number manipulation methods (such as toString(), split(), parseInt(), etc.), and with a time complexity of O(log n), where n is the given number.\n\n#Explanation#\nThis rewritte...
7
7