chosen
listlengths
2
2
rejected
listlengths
2
2
score_chosen
int64
6
9
score_rejected
int64
1
9
[ { "content": "Create a Node.js server that can handle multiple concurrent connections on port 8080. The server should be able to handle requests from multiple clients simultaneously without any data loss or corruption. The server should also support HTTPS connections.\n\nAdditionally, implement a session manage...
[ { "content": "Create a Node.js server that can handle multiple concurrent connections on port 8080. The server should be able to handle requests from multiple clients simultaneously without any data loss or corruption. The server should also support HTTPS connections.\n\nAdditionally, implement a session manage...
9
9
[ { "content": "You are given an object in JavaScript that may contain circular references. Your task is to write a function that converts the object to a JSON string, while also preserving the order of the object properties.\n\nThe function should have the following signature:\n\n```javascript\nfunction convertO...
[ { "content": "You are given an object in JavaScript that may contain circular references. Your task is to write a function that converts the object to a JSON string, while also preserving the order of the object properties.\n\nThe function should have the following signature:\n\n```javascript\nfunction convertO...
6
4
[ { "content": "Write a JavaScript function to count the number of occurrences of each character in a given string. The function should return an object where each key-value pair represents a character and its corresponding count. The function should also ignore any non-alphabetic characters and be case-sensitive...
[ { "content": "Write a JavaScript function to count the number of occurrences of each character in a given string. The function should return an object where each key-value pair represents a character and its corresponding count. The function should also ignore any non-alphabetic characters and be case-sensitive...
7
7
[ { "content": "Write a JavaScript function to check if a string contains the given substring in a case-sensitive manner, but the function should not use built-in string methods like includes() or indexOf().\n\nThe function should have a time complexity of O(n), where n is the length of the string.\n\n**Reference...
[ { "content": "Write a JavaScript function to check if a string contains the given substring in a case-sensitive manner, but the function should not use built-in string methods like includes() or indexOf().\n\nThe function should have a time complexity of O(n), where n is the length of the string.\n\n**Reference...
7
1
[ { "content": "Please write a function in JavaScript that takes a string as input and returns a new string with the color of all the headings changed to blue, all the paragraphs changed to red, and all the hyperlinks changed to green. You can assume that the input string will only contain valid HTML code.\n\nExa...
[ { "content": "Please write a function in JavaScript that takes a string as input and returns a new string with the color of all the headings changed to blue, all the paragraphs changed to red, and all the hyperlinks changed to green. You can assume that the input string will only contain valid HTML code.\n\nExa...
7
7
[ { "content": "Write a JavaScript function that sorts an array of strings alphabetically. The function should ignore the case of the strings and should also handle strings that contain special characters. Additionally, the function should return a new array instead of modifying the original array. The sorting sh...
[ { "content": "Write a JavaScript function that sorts an array of strings alphabetically. The function should ignore the case of the strings and should also handle strings that contain special characters. Additionally, the function should return a new array instead of modifying the original array. The sorting sh...
9
9
[ { "content": "Create a JavaScript program to convert temperatures between Celsius and Kelvin, using the formula: Kelvin = Celsius + 273.15. Your program should also validate that the input temperature is within the range of -273.15 to 1000 Celsius, and display an error message if the input is invalid. Additiona...
[ { "content": "Create a JavaScript program to convert temperatures between Celsius and Kelvin, using the formula: Kelvin = Celsius + 273.15. Your program should also validate that the input temperature is within the range of -273.15 to 1000 Celsius, and display an error message if the input is invalid. Additiona...
9
9
[ { "content": "Please write a full-stack web application that allows users to register for an account. The registration form should include fields for the user's name, email address, password, and phone number. Implement client-side validation to ensure that the email address is in the correct format and the pas...
[ { "content": "Please write a full-stack web application that allows users to register for an account. The registration form should include fields for the user's name, email address, password, and phone number. Implement client-side validation to ensure that the email address is in the correct format and the pas...
9
9
[ { "content": "What is the difference between variables declared with let and const in JavaScript? Provide an example of incorrect code that tries to reassign a value to a variable declared with const. Explain why the error occurs and how it can be fixed.\n\nPlease also explain the concept of \"hoisting\" in rel...
[ { "content": "What is the difference between variables declared with let and const in JavaScript? Provide an example of incorrect code that tries to reassign a value to a variable declared with const. Explain why the error occurs and how it can be fixed.\n\nPlease also explain the concept of \"hoisting\" in rel...
6
1
[ { "content": "Implement a function in JavaScript that takes in an array of integers and returns the maximum sum of a subarray within the given array.\n\nThe time complexity of your solution should be no more than O(n), where n is the length of the input array. Additionally, the space complexity of your solution...
[ { "content": "Implement a function in JavaScript that takes in an array of integers and returns the maximum sum of a subarray within the given array.\n\nThe time complexity of your solution should be no more than O(n), where n is the length of the input array. Additionally, the space complexity of your solution...
9
9
[ { "content": "Create a function in JavaScript that takes two strings as parameters and returns the concatenation of both strings. However, if the second string is a substring of the first string, remove that substring from the first string before concatenating them.\n\nAdditionally, if either of the strings is ...
[ { "content": "Create a function in JavaScript that takes two strings as parameters and returns the concatenation of both strings. However, if the second string is a substring of the first string, remove that substring from the first string before concatenating them.\n\nAdditionally, if either of the strings is ...
7
2
[ { "content": "Given a JSON structure with multiple objects, write a JavaScript function that returns an array of all the values of the property \"firstName\" if the value of the property \"age\" is greater than or equal to 18, the value of the property \"lastName\" is not an empty string, and the value of the p...
[ { "content": "Given a JSON structure with multiple objects, write a JavaScript function that returns an array of all the values of the property \"firstName\" if the value of the property \"age\" is greater than or equal to 18, the value of the property \"lastName\" is not an empty string, and the value of the p...
9
4
[ { "content": "let sum = 0;\nlet i = 0;\n\nif (i <= 10) {\n sum += i;\n i += 1;\n\n if (i <= 10) {\n sum += i;\n i += 1;\n\n if (i <= 10) {\n sum += i;\n i += 1;\n\n if (i <= 10) {\n sum += i;\n i += 1;\n\n if (i <= 10) {\n ...
[ { "content": "let sum = 0;\nlet i = 0;\n\nif (i <= 10) {\n sum += i;\n i += 1;\n\n if (i <= 10) {\n sum += i;\n i += 1;\n\n if (i <= 10) {\n sum += i;\n i += 1;\n\n if (i <= 10) {\n sum += i;\n i += 1;\n\n if (i <= 10) {\n ...
6
6
[ { "content": "Rearrange the following array of objects so that the output is sorted in ascending order by the \"age\" property. If two objects have the same age, then sort them in descending order by the \"name\" property. If two objects have the same age and the same name, then sort them in ascending order by ...
[ { "content": "Rearrange the following array of objects so that the output is sorted in ascending order by the \"age\" property. If two objects have the same age, then sort them in descending order by the \"name\" property. If two objects have the same age and the same name, then sort them in ascending order by ...
8
8
[ { "content": "Create a function in JavaScript that takes an array of integers as input. The function should return the sum of all the positive integers in the array. If the array contains any negative numbers, ignore them and continue with the iteration. \n\nConstraints:\n- The length of the input array should ...
[ { "content": "Create a function in JavaScript that takes an array of integers as input. The function should return the sum of all the positive integers in the array. If the array contains any negative numbers, ignore them and continue with the iteration. \n\nConstraints:\n- The length of the input array should ...
6
6
[ { "content": "Write a JavaScript function that takes an array of strings and returns a new array containing the length of each string. The function should have a time complexity of O(n), where n is the total number of characters in all the strings combined. Additionally, the function should not use any built-in...
[ { "content": "Write a JavaScript function that takes an array of strings and returns a new array containing the length of each string. The function should have a time complexity of O(n), where n is the total number of characters in all the strings combined. Additionally, the function should not use any built-in...
8
2
[ { "content": "Create a function in JavaScript to convert a given string to a positive or negative floating-point number in scientific notation. The string may contain non-digit characters in between the digits, at the beginning or end of the string, and may include a decimal point, a minus sign, or the letter \...
[ { "content": "Create a function in JavaScript to convert a given string to a positive or negative floating-point number in scientific notation. The string may contain non-digit characters in between the digits, at the beginning or end of the string, and may include a decimal point, a minus sign, or the letter \...
8
8
[ { "content": "Create a function in JavaScript to create a subset of a given array, but the subset must contain all possible combinations of k elements from the original array, where k is an even number between 2 and 10. Additionally, each combination must contain at least one element that is a prime number. The...
[ { "content": "Create a function in JavaScript to create a subset of a given array, but the subset must contain all possible combinations of k elements from the original array, where k is an even number between 2 and 10. Additionally, each combination must contain at least one element that is a prime number. The...
8
1
[ { "content": "Please implement a function in JavaScript to check if a given list of strings is a palindrome. The function should return true if the list is a palindrome, and false otherwise. A palindrome list is defined as a list where the concatenation of its elements in reverse order is the same as the origin...
[ { "content": "Please implement a function in JavaScript to check if a given list of strings is a palindrome. The function should return true if the list is a palindrome, and false otherwise. A palindrome list is defined as a list where the concatenation of its elements in reverse order is the same as the origin...
9
9
[ { "content": "Write a JavaScript method to return the sum of array elements, but do not use the built-in array methods like reduce(), sum(), or the addition operator (+). Additionally, you are not allowed to use any loops or recursion.", "role": "user" }, { "content": "One way to achieve this is by ...
[ { "content": "Write a JavaScript method to return the sum of array elements, but do not use the built-in array methods like reduce(), sum(), or the addition operator (+). Additionally, you are not allowed to use any loops or recursion.", "role": "user" }, { "content": "One way to achieve this is by ...
7
7
[ { "content": "Create a JavaScript function to simulate rolling a pair of fair dice with a random number generator, but restrict the outcome to only prime numbers. The function should return an array of all possible outcomes as pairs of prime numbers.\n\nFor example, if the dice are rolled 3 times, the function ...
[ { "content": "Create a JavaScript function to simulate rolling a pair of fair dice with a random number generator, but restrict the outcome to only prime numbers. The function should return an array of all possible outcomes as pairs of prime numbers.\n\nFor example, if the dice are rolled 3 times, the function ...
6
1
[ { "content": "Evaluate the sum and product of two numbers using a JavaScript expression. Additionally, calculate the sum and product of the sum and product of the two numbers. Print all the results. The numbers should be within the range of 1 to 100. The sum and product should not exceed 1000.", "role": "us...
[ { "content": "Evaluate the sum and product of two numbers using a JavaScript expression. Additionally, calculate the sum and product of the sum and product of the two numbers. Print all the results. The numbers should be within the range of 1 to 100. The sum and product should not exceed 1000.", "role": "us...
8
2
[ { "content": "Write a JavaScript function that takes in a number and a specific number of decimal places as parameters. The function should format the number to the specified decimal places and round it accordingly. The function should also handle negative numbers, numbers with a large number of decimal places,...
[ { "content": "Write a JavaScript function that takes in a number and a specific number of decimal places as parameters. The function should format the number to the specified decimal places and round it accordingly. The function should also handle negative numbers, numbers with a large number of decimal places,...
6
6
[ { "content": "Create a JavaScript function to extract the text from a given HTML element, but you cannot use any built-in HTML parsing libraries, regular expressions, or DOM manipulation methods such as `querySelector`, `getElementById`, or `innerHTML`. Additionally, the function should handle nested HTML eleme...
[ { "content": "Create a JavaScript function to extract the text from a given HTML element, but you cannot use any built-in HTML parsing libraries, regular expressions, or DOM manipulation methods such as `querySelector`, `getElementById`, or `innerHTML`. Additionally, the function should handle nested HTML eleme...
6
6
[ { "content": "Write a JavaScript function that extracts the unique prime numbers from a given string, while ignoring any non-alphanumeric characters. The function should meet the following requirements:\n\n1. The function should return an array containing all the extracted prime numbers in ascending order.\n2. ...
[ { "content": "Write a JavaScript function that extracts the unique prime numbers from a given string, while ignoring any non-alphanumeric characters. The function should meet the following requirements:\n\n1. The function should return an array containing all the extracted prime numbers in ascending order.\n2. ...
8
8
[ { "content": "Write a JavaScript program to convert month numbers to month names. However, you are not allowed to use any built-in JavaScript functions or libraries that directly provide month names. Additionally, you cannot use arrays or other data structures to store the month names. You have to implement the...
[ { "content": "Write a JavaScript program to convert month numbers to month names. However, you are not allowed to use any built-in JavaScript functions or libraries that directly provide month names. Additionally, you cannot use arrays or other data structures to store the month names. You have to implement the...
6
4
[ { "content": "Create a JavaScript function to accept a range of numbers (from 1 to 10000) and display all the prime numbers within that range. The function should also calculate the sum of all the prime numbers and display it along with the list of prime numbers. Additionally, the function should optimize the c...
[ { "content": "Create a JavaScript function to accept a range of numbers (from 1 to 10000) and display all the prime numbers within that range. The function should also calculate the sum of all the prime numbers and display it along with the list of prime numbers. Additionally, the function should optimize the c...
7
4
[ { "content": "Write a program in JavaScript that prints out the first 20 prime numbers.", "role": "user" }, { "content": "Here's a JavaScript program that prints out the first 20 prime numbers:\n\n```javascript\nfunction isPrime(num) {\n if (num <= 1) {\n return false;\n }\n\n for (let i = 2; ...
[ { "content": "Write a program in JavaScript that prints out the first 20 prime numbers.", "role": "user" }, { "content": "Here's a JavaScript program that prints out the first 20 prime numbers:\n\n```javascript\nfunction isPrime(num) {\n if (num <= 1) {\n return false;\n }\n\n for (let i = 2; ...
7
7
[ { "content": "Create a JavaScript function called \"createUser\" that takes in four parameters: name, age, location, and hobbies. The function should validate the input and return an object with properties name, age, location, and hobbies.\n\nThe name parameter must be a string containing at least 3 characters ...
[ { "content": "Create a JavaScript function called \"createUser\" that takes in four parameters: name, age, location, and hobbies. The function should validate the input and return an object with properties name, age, location, and hobbies.\n\nThe name parameter must be a string containing at least 3 characters ...
9
1
[ { "content": "Create a JavaScript program to validate the username entered by the user, which must meet the following criteria:\n1. The username must be between 8 and 16 characters long.\n2. The username must start with a letter (a-z or A-Z).\n3. The username can only contain letters, numbers, underscores, or h...
[ { "content": "Create a JavaScript program to validate the username entered by the user, which must meet the following criteria:\n1. The username must be between 8 and 16 characters long.\n2. The username must start with a letter (a-z or A-Z).\n3. The username can only contain letters, numbers, underscores, or h...
7
7
[ { "content": "Write a JavaScript program to calculate the sum of the first 10,000 prime numbers that are also palindrome numbers, excluding any prime numbers that contain the digit \"5\". A palindrome number is a number that remains the same when its digits are reversed. Additionally, the program should output ...
[ { "content": "Write a JavaScript program to calculate the sum of the first 10,000 prime numbers that are also palindrome numbers, excluding any prime numbers that contain the digit \"5\". A palindrome number is a number that remains the same when its digits are reversed. Additionally, the program should output ...
8
8
[ { "content": "Write a JavaScript function that toggles the visibility of a div element. The div element should fade in and out smoothly using CSS transitions. Implement the function in such a way that it can handle multiple div elements on the same page, each with their own individual fade-in and fade-out durat...
[ { "content": "Write a JavaScript function that toggles the visibility of a div element. The div element should fade in and out smoothly using CSS transitions. Implement the function in such a way that it can handle multiple div elements on the same page, each with their own individual fade-in and fade-out durat...
7
7
[ { "content": "Correct the syntax errors in the following JavaScript snippet and refactor the code to use a switch statement instead of an if-else statement. Additionally, ensure that the variable \"outpt\" is declared as a constant and initialize it to 0 before the conditionals. The code should also be optimize...
[ { "content": "Correct the syntax errors in the following JavaScript snippet and refactor the code to use a switch statement instead of an if-else statement. Additionally, ensure that the variable \"outpt\" is declared as a constant and initialize it to 0 before the conditionals. The code should also be optimize...
9
3
[ { "content": "Generate a function to convert a given number of milliseconds into a time format string in JavaScript, but the time format should include microseconds as well. The time format should follow the format \"HH:MM:SS:SSS:UUU\", where HH represents hours, MM represents minutes, SS represents seconds, SS...
[ { "content": "Generate a function to convert a given number of milliseconds into a time format string in JavaScript, but the time format should include microseconds as well. The time format should follow the format \"HH:MM:SS:SSS:UUU\", where HH represents hours, MM represents minutes, SS represents seconds, SS...
6
6
[ { "content": "Generate a JavaScript program to check if a number is within a given range, but the lower bound and upper bound values can be dynamic and can only be prime numbers. Additionally, the program should validate if the given range is a consecutive prime number range.", "role": "user" }, { "...
[ { "content": "Generate a JavaScript program to check if a number is within a given range, but the lower bound and upper bound values can be dynamic and can only be prime numbers. Additionally, the program should validate if the given range is a consecutive prime number range.", "role": "user" }, { "...
6
6
[ { "content": "Use jQuery to toggle a div with the class 'hide' only if it is not currently animated and has a data attribute 'toggleable' set to true. Additionally, check if the div has a sibling element with a class of 'visible', and if it does, fade out the sibling element before toggling the div with the cla...
[ { "content": "Use jQuery to toggle a div with the class 'hide' only if it is not currently animated and has a data attribute 'toggleable' set to true. Additionally, check if the div has a sibling element with a class of 'visible', and if it does, fade out the sibling element before toggling the div with the cla...
9
4
[ { "content": "Write a JavaScript program to detect the browser type and version, and also determine if the browser supports certain features like HTML5 and CSS3. Additionally, the program should be able to handle any future browser types that may be released.\n\nProvide a piece of erroneous code that tries to d...
[ { "content": "Write a JavaScript program to detect the browser type and version, and also determine if the browser supports certain features like HTML5 and CSS3. Additionally, the program should be able to handle any future browser types that may be released.\n\nProvide a piece of erroneous code that tries to d...
6
6
[ { "content": "Generate a random array of 1000 integers using JavaScript. Additionally, sort the array in descending order and remove any duplicate values from the array. You should not use any built-in array sorting or removing duplicate methods or functions. The time complexity of your solution should be O(n^2...
[ { "content": "Generate a random array of 1000 integers using JavaScript. Additionally, sort the array in descending order and remove any duplicate values from the array. You should not use any built-in array sorting or removing duplicate methods or functions. The time complexity of your solution should be O(n^2...
9
9
[ { "content": "Write a JavaScript function for validating an email address. The function should not rely on built-in JavaScript methods or regular expressions for email validation. Instead, it should manually check the validity of the email address using string manipulation and logical operations. Additionally, ...
[ { "content": "Write a JavaScript function for validating an email address. The function should not rely on built-in JavaScript methods or regular expressions for email validation. Instead, it should manually check the validity of the email address using string manipulation and logical operations. Additionally, ...
9
9
[ { "content": "Design a data structure using JavaScript to represent a binary tree. Additionally, implement the following methods:\n1. `insert(value)`: Inserts a new node with the given value into the binary tree. Each value in the binary tree should be unique, and attempting to insert a duplicate value should r...
[ { "content": "Design a data structure using JavaScript to represent a binary tree. Additionally, implement the following methods:\n1. `insert(value)`: Inserts a new node with the given value into the binary tree. Each value in the binary tree should be unique, and attempting to insert a duplicate value should r...
7
2
[ { "content": "Generate a function which takes an array of numbers and returns the smallest number. However, you are not allowed to use any conditional statements (such as if/else or switch) or any built-in functions that directly solve this problem (such as min() or Math.min()).\n\nAdditionally, the function sh...
[ { "content": "Generate a function which takes an array of numbers and returns the smallest number. However, you are not allowed to use any conditional statements (such as if/else or switch) or any built-in functions that directly solve this problem (such as min() or Math.min()).\n\nAdditionally, the function sh...
9
9
[ { "content": "Write a CSS class that changes the background color of a div to green and sets the font color to white. This class should only apply to div elements with a specific id attribute called \"myDiv\". Additionally, the class should add a 2px solid border around the div with a border color of black. How...
[ { "content": "Write a CSS class that changes the background color of a div to green and sets the font color to white. This class should only apply to div elements with a specific id attribute called \"myDiv\". Additionally, the class should add a 2px solid border around the div with a border color of black. How...
8
8
[ { "content": "Write a JavaScript code to compare the values of two strings. Additionally, the code should also compare the lengths of the two strings and display a message indicating which string is longer or if they have the same length. However, you are not allowed to use any built-in string comparison functi...
[ { "content": "Write a JavaScript code to compare the values of two strings. Additionally, the code should also compare the lengths of the two strings and display a message indicating which string is longer or if they have the same length. However, you are not allowed to use any built-in string comparison functi...
7
7
[ { "content": "Write a JavaScript function to find the longest common subsequence between two given sequences.\n\nsequence1 = [1, 3, 5, 7, 9, 11]\nsequence2 = [2, 4, 6, 8, 10, 12]\n\nExample:\nInput:\nsequence1 = [1, 3, 5, 7, 9, 11]\nsequence2 = [2, 4, 6, 8, 10, 12]\nOutput:\n[]\n\nNote: The output should be an ...
[ { "content": "Write a JavaScript function to find the longest common subsequence between two given sequences.\n\nsequence1 = [1, 3, 5, 7, 9, 11]\nsequence2 = [2, 4, 6, 8, 10, 12]\n\nExample:\nInput:\nsequence1 = [1, 3, 5, 7, 9, 11]\nsequence2 = [2, 4, 6, 8, 10, 12]\nOutput:\n[]\n\nNote: The output should be an ...
9
9
[ { "content": "Write a JavaScript code to merge two sorted arrays into a third array, ensuring that no duplicates are present. The merged array should be sorted in descending order. The input arrays must contain only unique elements and have a maximum length of 100. The merged array should have a maximum length ...
[ { "content": "Write a JavaScript code to merge two sorted arrays into a third array, ensuring that no duplicates are present. The merged array should be sorted in descending order. The input arrays must contain only unique elements and have a maximum length of 100. The merged array should have a maximum length ...
8
8
[ { "content": "Create a JavaScript code snippet to generate a random number between 100 and 1000, but ensure that the generated number is always a prime number. Additionally, implement a function to check if a given number is a prime number and use it in your solution. The prime number checking function should h...
[ { "content": "Create a JavaScript code snippet to generate a random number between 100 and 1000, but ensure that the generated number is always a prime number. Additionally, implement a function to check if a given number is a prime number and use it in your solution. The prime number checking function should h...
9
9
[ { "content": "Create a JavaScript program that takes in an array of boolean values and toggles each value. Return the modified array. The program should also check if the length of the input array is prime and throw an error if it is not. Additionally, the program should throw an error if any of the boolean val...
[ { "content": "Create a JavaScript program that takes in an array of boolean values and toggles each value. Return the modified array. The program should also check if the length of the input array is prime and throw an error if it is not. Additionally, the program should throw an error if any of the boolean val...
6
6
[ { "content": "Create an algorithm using JavaScript that finds the largest prime number in an array, but do not use the built-in Math.max() method. The array may contain negative numbers and can have a length up to 1000.\n\nAdditionally, the algorithm should be optimized to have a time complexity of O(n), where ...
[ { "content": "Create an algorithm using JavaScript that finds the largest prime number in an array, but do not use the built-in Math.max() method. The array may contain negative numbers and can have a length up to 1000.\n\nAdditionally, the algorithm should be optimized to have a time complexity of O(n), where ...
8
8
[ { "content": "Create a JavaScript function that takes in an array of objects as an argument and counts the occurrence of a given element based on a specific property of the objects. The function should only count the occurrence of the given element if it is an exact match in terms of case. \n\nThe function shou...
[ { "content": "Create a JavaScript function that takes in an array of objects as an argument and counts the occurrence of a given element based on a specific property of the objects. The function should only count the occurrence of the given element if it is an exact match in terms of case. \n\nThe function shou...
7
7
[ { "content": "Write a script in JavaScript for reversing an array without using any built-in array manipulation methods or additional data structures. The solution should have a time complexity of O(n) and a space complexity of O(1). Additionally, you are not allowed to use any loop structures such as for, whil...
[ { "content": "Write a script in JavaScript for reversing an array without using any built-in array manipulation methods or additional data structures. The solution should have a time complexity of O(n) and a space complexity of O(1). Additionally, you are not allowed to use any loop structures such as for, whil...
9
9
[ { "content": "Given a string, write a JavaScript function to remove all duplicate characters from the string, without using any built-in array methods or regular expressions. The function should have a time complexity of O(n).\n\n#Additional Instructions#\n1. The function should only remove duplicate characters...
[ { "content": "Given a string, write a JavaScript function to remove all duplicate characters from the string, without using any built-in array methods or regular expressions. The function should have a time complexity of O(n).\n\n#Additional Instructions#\n1. The function should only remove duplicate characters...
7
7
[ { "content": "Suggest a function in JavaScript for repeating a given string a specified number of times, but the string must contain only unique characters and the number of times to repeat must be a prime number. Additionally, the function should handle cases where the given string may contain non-alphanumeric...
[ { "content": "Suggest a function in JavaScript for repeating a given string a specified number of times, but the string must contain only unique characters and the number of times to repeat must be a prime number. Additionally, the function should handle cases where the given string may contain non-alphanumeric...
8
8
[ { "content": "Given an array of numbers, write a JavaScript function to replace all occurrences of a specific number with another number. The function should return the modified array.\n\nExample:\nInput: replaceElements([1, 2, 3, 4, 3, 5, 6], 3, 7)\nOutput: [1, 2, 7, 4, 7, 5, 6]\n\nAdditional Requirements:\n1....
[ { "content": "Given an array of numbers, write a JavaScript function to replace all occurrences of a specific number with another number. The function should return the modified array.\n\nExample:\nInput: replaceElements([1, 2, 3, 4, 3, 5, 6], 3, 7)\nOutput: [1, 2, 7, 4, 7, 5, 6]\n\nAdditional Requirements:\n1....
9
4
[ { "content": "Suggest a loop in JavaScript for traversing an array of objects and printing out specific properties of each object. However, the loop should only print out properties that have a numeric value greater than 100.\n\nAdditional Instructions:\n1. The array of objects should have at least 20 objects.\...
[ { "content": "Suggest a loop in JavaScript for traversing an array of objects and printing out specific properties of each object. However, the loop should only print out properties that have a numeric value greater than 100.\n\nAdditional Instructions:\n1. The array of objects should have at least 20 objects.\...
9
9
[ { "content": "Write a JavaScript function that takes a string as input and returns the reverse of the string. You are not allowed to use any built-in string reverse function or any other built-in function that directly solves the problem. You should implement your own logic to reverse the string. Your function ...
[ { "content": "Write a JavaScript function that takes a string as input and returns the reverse of the string. You are not allowed to use any built-in string reverse function or any other built-in function that directly solves the problem. You should implement your own logic to reverse the string. Your function ...
6
6
[ { "content": "Using JavaScript, create a function that takes in an array of numbers as the first argument and a single number as the second argument. The function should return the number from the array that is closest to the second argument, but only if it is larger than the second argument. If there is no num...
[ { "content": "Using JavaScript, create a function that takes in an array of numbers as the first argument and a single number as the second argument. The function should return the number from the array that is closest to the second argument, but only if it is larger than the second argument. If there is no num...
9
9
[ { "content": "Create a function in JavaScript that takes three parameters: a start number, an end number, and a maximum range. The function should return an array of all prime numbers within the given range.\n\nAdditionally, you should implement the Sieve of Eratosthenes algorithm to find the prime numbers effi...
[ { "content": "Create a function in JavaScript that takes three parameters: a start number, an end number, and a maximum range. The function should return an array of all prime numbers within the given range.\n\nAdditionally, you should implement the Sieve of Eratosthenes algorithm to find the prime numbers effi...
6
1
[ { "content": "Write a function definition in JavaScript that calculates the factorial of a number. The factorial of a number is the product of all positive integers less than or equal to the number. The function should have a time complexity of O(n) and should not use any built-in JavaScript functions or librar...
[ { "content": "Write a function definition in JavaScript that calculates the factorial of a number. The factorial of a number is the product of all positive integers less than or equal to the number. The function should have a time complexity of O(n) and should not use any built-in JavaScript functions or librar...
9
2
[ { "content": "Write a JavaScript function that takes two parameters: an array of positive integers and a single positive integer. The function should return an array containing only the elements of the given array that are divisible by the second parameter without any remainder. The function should also remove ...
[ { "content": "Write a JavaScript function that takes two parameters: an array of positive integers and a single positive integer. The function should return an array containing only the elements of the given array that are divisible by the second parameter without any remainder. The function should also remove ...
9
9
[ { "content": "Please write a JavaScript function that takes an array of integers as input and sorts it in ascending order using the Bubble Sort algorithm. The function should have the following additional steps:\n\n1. Initialize a boolean variable \"swapped\" to true.\n2. Create a while loop that continues as l...
[ { "content": "Please write a JavaScript function that takes an array of integers as input and sorts it in ascending order using the Bubble Sort algorithm. The function should have the following additional steps:\n\n1. Initialize a boolean variable \"swapped\" to true.\n2. Create a while loop that continues as l...
7
4
[ { "content": "Write a JavaScript function that redirects the user to a specific URL after a specified amount of time has passed. The function should take two parameters: the URL to redirect to and the duration in milliseconds. The page should automatically redirect to the specified URL after the specified durat...
[ { "content": "Write a JavaScript function that redirects the user to a specific URL after a specified amount of time has passed. The function should take two parameters: the URL to redirect to and the duration in milliseconds. The page should automatically redirect to the specified URL after the specified durat...
9
9
[ { "content": "Create an array of 100,000 string objects in JavaScript with randomly generated values. Each string value should be a combination of uppercase letters, lowercase letters, digits, and special characters, with a length between 8 and 15 characters. Additionally, each string value must contain at leas...
[ { "content": "Create an array of 100,000 string objects in JavaScript with randomly generated values. Each string value should be a combination of uppercase letters, lowercase letters, digits, and special characters, with a length between 8 and 15 characters. Additionally, each string value must contain at leas...
7
7
[ { "content": "Given a string in JavaScript, write a function to reverse the string without using any built-in functions or methods. Your implementation should be efficient in terms of time and space complexity.\n\nPlease note that your solution should have a time complexity of O(n), where n is the length of the...
[ { "content": "Given a string in JavaScript, write a function to reverse the string without using any built-in functions or methods. Your implementation should be efficient in terms of time and space complexity.\n\nPlease note that your solution should have a time complexity of O(n), where n is the length of the...
8
8
[ { "content": "Rewrite the code in JavaScript to remove the first and last characters from a string, while also converting the remaining characters to uppercase and sorting them in reverse alphabetical order. Additionally, handle cases where the string contains numbers or special characters. The sorting should b...
[ { "content": "Rewrite the code in JavaScript to remove the first and last characters from a string, while also converting the remaining characters to uppercase and sorting them in reverse alphabetical order. Additionally, handle cases where the string contains numbers or special characters. The sorting should b...
9
9
[ { "content": "Write a function in JavaScript that generates a random number between 1 and 1000. The generated number should be stored in a constant variable using the \"const\" keyword and should not be able to be reassigned to a different value. The function should be called \"generateRandomNumber\" and should...
[ { "content": "Write a function in JavaScript that generates a random number between 1 and 1000. The generated number should be stored in a constant variable using the \"const\" keyword and should not be able to be reassigned to a different value. The function should be called \"generateRandomNumber\" and should...
9
9
[ { "content": "Create a JavaScript function that takes two parameters, a string and an array of integers, and returns a new string where each character in the original string is repeated a number of times specified by the corresponding element in the array. However, if any element in the array is negative or gre...
[ { "content": "Create a JavaScript function that takes two parameters, a string and an array of integers, and returns a new string where each character in the original string is repeated a number of times specified by the corresponding element in the array. However, if any element in the array is negative or gre...
7
3
[ { "content": "Create an array of 1000 random integers in JavaScript between -1000 and 1000. \nAfter creating the array, remove all the duplicates from it, ensuring that the solution has a time complexity of O(n).\nThen, sort the array in ascending order using a sorting algorithm of your choice, ensuring that th...
[ { "content": "Create an array of 1000 random integers in JavaScript between -1000 and 1000. \nAfter creating the array, remove all the duplicates from it, ensuring that the solution has a time complexity of O(n).\nThen, sort the array in ascending order using a sorting algorithm of your choice, ensuring that th...
7
7
[ { "content": "What is the return type of a Javascript function that returns the sum of three integers and a string concatenation of three strings, while ensuring that the sum of the integers is a prime number, the length of the concatenated string is greater than 20 characters, and the sum of the ASCII values o...
[ { "content": "What is the return type of a Javascript function that returns the sum of three integers and a string concatenation of three strings, while ensuring that the sum of the integers is a prime number, the length of the concatenated string is greater than 20 characters, and the sum of the ASCII values o...
9
2
[ { "content": "Write a function in JavaScript that takes two arrays as input and returns true if they have the same elements in the same order, and false otherwise. The arrays can contain any type of values, including nested arrays and objects. Additionally, the solution should not use any built-in JavaScript ar...
[ { "content": "Write a function in JavaScript that takes two arrays as input and returns true if they have the same elements in the same order, and false otherwise. The arrays can contain any type of values, including nested arrays and objects. Additionally, the solution should not use any built-in JavaScript ar...
8
4
[ { "content": "Create a JavaScript program to validate an IP address, ensuring that it is a valid IPv4 address, that it is not a private IP address, that it is not a reserved IP address, that it is not a multicast IP address, and that it is not a loopback IP address.\n\nTo validate an IP address, you need to per...
[ { "content": "Create a JavaScript program to validate an IP address, ensuring that it is a valid IPv4 address, that it is not a private IP address, that it is not a reserved IP address, that it is not a multicast IP address, and that it is not a loopback IP address.\n\nTo validate an IP address, you need to per...
8
4
[ { "content": "Create a function in JavaScript to subtract two dates and return the difference in hours, minutes, and seconds, taking into account daylight saving time changes and different time zones. The function should also handle scenarios where one or both of the dates are in different time zones, and conve...
[ { "content": "Create a function in JavaScript to subtract two dates and return the difference in hours, minutes, and seconds, taking into account daylight saving time changes and different time zones. The function should also handle scenarios where one or both of the dates are in different time zones, and conve...
9
9
[ { "content": "Create a JavaScript function to calculate the total price of an order, taking into account the following additional requirements:\n- The function should throw an error if any item in the order has a price less than or equal to zero, or if the quantity of any item is less than zero.\n- The function...
[ { "content": "Create a JavaScript function to calculate the total price of an order, taking into account the following additional requirements:\n- The function should throw an error if any item in the order has a price less than or equal to zero, or if the quantity of any item is less than zero.\n- The function...
7
7
[ { "content": "Parse the following JSON string and create a JavaScript object. Additionally, add a nested object within the original object with the key \"address\" and the value of another JavaScript object containing the keys \"street\", \"city\", \"country\", \"postalCode\", \"latitude\", and \"longitude\". T...
[ { "content": "Parse the following JSON string and create a JavaScript object. Additionally, add a nested object within the original object with the key \"address\" and the value of another JavaScript object containing the keys \"street\", \"city\", \"country\", \"postalCode\", \"latitude\", and \"longitude\". T...
6
6
[ { "content": "Create a JSON object with the following properties: name, age, hobby, and a nested object called \"address\" which contains the properties: street, city, state, and postal code.\n\nIn addition, add a property called \"phone numbers\" which is an array of objects. Each object in the array should ha...
[ { "content": "Create a JSON object with the following properties: name, age, hobby, and a nested object called \"address\" which contains the properties: street, city, state, and postal code.\n\nIn addition, add a property called \"phone numbers\" which is an array of objects. Each object in the array should ha...
7
1
[ { "content": "You need to read a given string and convert it to an appropriate list object in JavaScript. The converted list should only contain unique elements and must be sorted in descending order. Additionally, any leading or trailing whitespaces in the string should be removed before conversion. \n\nWrite ...
[ { "content": "You need to read a given string and convert it to an appropriate list object in JavaScript. The converted list should only contain unique elements and must be sorted in descending order. Additionally, any leading or trailing whitespaces in the string should be removed before conversion. \n\nWrite ...
8
4
[ { "content": "Create a Node.js server that serves up a webpage when a GET request is received. The webpage should be dynamically generated and include real-time data from an external API. The server should also implement user authentication using JWT tokens. Additionally, implement a custom rate limiter middlew...
[ { "content": "Create a Node.js server that serves up a webpage when a GET request is received. The webpage should be dynamically generated and include real-time data from an external API. The server should also implement user authentication using JWT tokens. Additionally, implement a custom rate limiter middlew...
6
6
[ { "content": "Please write a JavaScript function called `isPrime` that takes a number as input and returns `true` if the number is prime, and `false` otherwise. You cannot use any built-in JavaScript functions or libraries to determine if a number is prime.\n\nThen, use the `isPrime` function to create an array...
[ { "content": "Please write a JavaScript function called `isPrime` that takes a number as input and returns `true` if the number is prime, and `false` otherwise. You cannot use any built-in JavaScript functions or libraries to determine if a number is prime.\n\nThen, use the `isPrime` function to create an array...
6
6
[ { "content": "Write a JavaScript callback function that accepts an array of messages as a parameter. The function should randomly select a message from the array and alert it. The function should also keep track of the messages that have already been alerted and ensure that the same message is not alerted twice...
[ { "content": "Write a JavaScript callback function that accepts an array of messages as a parameter. The function should randomly select a message from the array and alert it. The function should also keep track of the messages that have already been alerted and ensure that the same message is not alerted twice...
7
4
[ { "content": "Create a JavaScript class to generate random numbers within a specific range and with a specific distribution. The class should allow the user to set the minimum and maximum values for the generated numbers, as well as the desired distribution (e.g., normal distribution, exponential distribution, ...
[ { "content": "Create a JavaScript class to generate random numbers within a specific range and with a specific distribution. The class should allow the user to set the minimum and maximum values for the generated numbers, as well as the desired distribution (e.g., normal distribution, exponential distribution, ...
8
1
[ { "content": "Write a function in JavaScript to remove all vowels from an input string, while preserving the original case of the letters. The function should have a time complexity of O(n), where n is the length of the input string.\n\nAdditionally, ensure that the function can handle multiple whitespace chara...
[ { "content": "Write a function in JavaScript to remove all vowels from an input string, while preserving the original case of the letters. The function should have a time complexity of O(n), where n is the length of the input string.\n\nAdditionally, ensure that the function can handle multiple whitespace chara...
6
6
[ { "content": "Develop a JavaScript code snippet to find the maximum and minimum numbers in an array, while also ensuring that the array contains only unique values and that the length of the array is at least 5.\n\nThe array should be populated with randomly generated integers within a given range. The range sh...
[ { "content": "Develop a JavaScript code snippet to find the maximum and minimum numbers in an array, while also ensuring that the array contains only unique values and that the length of the array is at least 5.\n\nThe array should be populated with randomly generated integers within a given range. The range sh...
8
1
[ { "content": "Create a responsive web page using HTML, CSS, and JavaScript that displays a user's full name and age in a visually appealing format. The full name and age should be centered horizontally and vertically on the page. The full name should be displayed in uppercase, with a larger font size, and the a...
[ { "content": "Create a responsive web page using HTML, CSS, and JavaScript that displays a user's full name and age in a visually appealing format. The full name and age should be centered horizontally and vertically on the page. The full name should be displayed in uppercase, with a larger font size, and the a...
7
7
[ { "content": "Design a Node.js program that calculates the factorial of a number using recursion and handles extremely large numbers efficiently.\n\nTime Complexity Requirement: The program should have a time complexity of O(n) or better.\n\nSpace Complexity Requirement: The program should have a space complexi...
[ { "content": "Design a Node.js program that calculates the factorial of a number using recursion and handles extremely large numbers efficiently.\n\nTime Complexity Requirement: The program should have a time complexity of O(n) or better.\n\nSpace Complexity Requirement: The program should have a space complexi...
9
9
[ { "content": "Create a JavaScript object for employee records with the following properties: name, age, department, and salary. Implement the following methods for the object:\n\n1. getDetails(): This method should return a string with the employee's name, age, department, and salary.\n\n2. changeDepartment(new...
[ { "content": "Create a JavaScript object for employee records with the following properties: name, age, department, and salary. Implement the following methods for the object:\n\n1. getDetails(): This method should return a string with the employee's name, age, department, and salary.\n\n2. changeDepartment(new...
9
9
[ { "content": "Create a program in JavaScript to remove the duplicate entries in an array, but without using any built-in array methods such as filter, reduce, or splice. Additionally, ensure that the program runs in O(n) time complexity, where n is the length of the array.\n\narr = [1, 2, 3, 1, 4, 5, 6, 4, 1]\n...
[ { "content": "Create a program in JavaScript to remove the duplicate entries in an array, but without using any built-in array methods such as filter, reduce, or splice. Additionally, ensure that the program runs in O(n) time complexity, where n is the length of the array.\n\narr = [1, 2, 3, 1, 4, 5, 6, 4, 1]\n...
7
7
[ { "content": "Write a JavaScript function to find all the even numbers from a given array of integers and return them in descending order.\n\n[3, 12, 17, 24, 4, 10, -8, 5, 2, \"7\", null]\n\nAdditional Requirements:\n1. The function should not modify the original array.\n2. The function should ignore non-intege...
[ { "content": "Write a JavaScript function to find all the even numbers from a given array of integers and return them in descending order.\n\n[3, 12, 17, 24, 4, 10, -8, 5, 2, \"7\", null]\n\nAdditional Requirements:\n1. The function should not modify the original array.\n2. The function should ignore non-intege...
9
9
[ { "content": "Construct a loop statement in JavaScript that prints each word in the given array and its corresponding index. Additionally, the loop should only print words that are longer than 5 characters and contain at least two vowels. The output should be formatted as \"Index: Word\". The loop should also t...
[ { "content": "Construct a loop statement in JavaScript that prints each word in the given array and its corresponding index. Additionally, the loop should only print words that are longer than 5 characters and contain at least two vowels. The output should be formatted as \"Index: Word\". The loop should also t...
9
3
[ { "content": "Write JavaScript code to add the following data to the web page in a formatted table. Each table row should display the name, age, country, and occupation of each person. Additionally, calculate and display the average age and average age of retirement of all the people in the table. Sort the tabl...
[ { "content": "Write JavaScript code to add the following data to the web page in a formatted table. Each table row should display the name, age, country, and occupation of each person. Additionally, calculate and display the average age and average age of retirement of all the people in the table. Sort the tabl...
7
7
[ { "content": "Write a JavaScript function to randomize the order of elements in an array, ensuring that no two consecutive elements in the randomized array have the same starting letter. If a consecutive pair with the same starting letter is found, swap one of the elements with another randomly chosen element i...
[ { "content": "Write a JavaScript function to randomize the order of elements in an array, ensuring that no two consecutive elements in the randomized array have the same starting letter. If a consecutive pair with the same starting letter is found, swap one of the elements with another randomly chosen element i...
7
7
[ { "content": "Construct a for loop in JavaScript that adds the values in the given array, but the loop should only iterate over the odd indices of the array. Additionally, you should only use the reduce function to calculate the sum. The final sum should be stored in a variable named \"totalSum\". \n\nYou are n...
[ { "content": "Construct a for loop in JavaScript that adds the values in the given array, but the loop should only iterate over the odd indices of the array. Additionally, you should only use the reduce function to calculate the sum. The final sum should be stored in a variable named \"totalSum\". \n\nYou are n...
9
9
[ { "content": "Please use JavaScript to separate the given array into three arrays: one containing the prime numbers, one containing the composite numbers, and one containing the perfect numbers. The output arrays should be sorted in ascending order.\n\nA perfect number is a positive integer that is equal to the...
[ { "content": "Please use JavaScript to separate the given array into three arrays: one containing the prime numbers, one containing the composite numbers, and one containing the perfect numbers. The output arrays should be sorted in ascending order.\n\nA perfect number is a positive integer that is equal to the...
6
6
[ { "content": "Create a function in JavaScript that returns the third highest number from the given list. \n\nAdditional Step 1:\nSort the list in ascending order.\n\nAdditional Step 2:\nIf the sorted list contains duplicates, remove all duplicate elements.\n\nAdditional Step 3:\nIf the sorted list contains less...
[ { "content": "Create a function in JavaScript that returns the third highest number from the given list. \n\nAdditional Step 1:\nSort the list in ascending order.\n\nAdditional Step 2:\nIf the sorted list contains duplicates, remove all duplicate elements.\n\nAdditional Step 3:\nIf the sorted list contains less...
8
8
[ { "content": "Please write a JavaScript function that takes in a date as a parameter and returns the date formatted in the following format: \"Day of the week, Month DD, YYYY, HH:MM:SS\". The input date will always be a valid date.\n\nAdditionally, the function should support localization, meaning it should be ...
[ { "content": "Please write a JavaScript function that takes in a date as a parameter and returns the date formatted in the following format: \"Day of the week, Month DD, YYYY, HH:MM:SS\". The input date will always be a valid date.\n\nAdditionally, the function should support localization, meaning it should be ...
7
7
[ { "content": "Describe which programming language and libraries/frameworks could be best suited for a web scraping task, taking into consideration the need to handle JavaScript-heavy websites and efficiently parse and analyze large amounts of data. Additionally, explain how you would handle dynamic content, pag...
[ { "content": "Describe which programming language and libraries/frameworks could be best suited for a web scraping task, taking into consideration the need to handle JavaScript-heavy websites and efficiently parse and analyze large amounts of data. Additionally, explain how you would handle dynamic content, pag...
8
8
[ { "content": "Write a function in JavaScript that finds the length of a string, without using any built-in methods or properties specifically designed to find the length of a string. Additionally, the function should only count alphanumeric characters (i.e. letters and numbers) in the string and ignore any spec...
[ { "content": "Write a function in JavaScript that finds the length of a string, without using any built-in methods or properties specifically designed to find the length of a string. Additionally, the function should only count alphanumeric characters (i.e. letters and numbers) in the string and ignore any spec...
7
7
[ { "content": "Implement a custom sorting algorithm to sort the following array in ascending order using only bitwise operations in JavaScript. The algorithm should have a time complexity of O(nlogn) and use a constant amount of extra space. The implementation should not use any built-in sorting functions or lib...
[ { "content": "Implement a custom sorting algorithm to sort the following array in ascending order using only bitwise operations in JavaScript. The algorithm should have a time complexity of O(nlogn) and use a constant amount of extra space. The implementation should not use any built-in sorting functions or lib...
9
2
[ { "content": "Write a JavaScript function that capitalizes the first letter of each word in a given string and also removes any extra spaces between words. The function should handle words with mixed case, such as \"JaVaScRiPt\" or \"wEb DeVeLoPmEnT\", and capitalize the first letter of each word, regardless of...
[ { "content": "Write a JavaScript function that capitalizes the first letter of each word in a given string and also removes any extra spaces between words. The function should handle words with mixed case, such as \"JaVaScRiPt\" or \"wEb DeVeLoPmEnT\", and capitalize the first letter of each word, regardless of...
7
7
[ { "content": "Write a function in JavaScript that takes a string as input and returns an object with each character as the key and the frequency as the value. The function should also ignore case sensitivity. Additionally, the function should handle special characters and whitespace.\n\nFor example, given the i...
[ { "content": "Write a function in JavaScript that takes a string as input and returns an object with each character as the key and the frequency as the value. The function should also ignore case sensitivity. Additionally, the function should handle special characters and whitespace.\n\nFor example, given the i...
9
9
[ { "content": "Create a function that takes two parameters, an array and an element, and checks if the element exists in the array. The function should return the index of the element if it is found in the array, and -1 otherwise. You may not use any built-in array search methods (e.g. indexOf, includes) to solv...
[ { "content": "Create a function that takes two parameters, an array and an element, and checks if the element exists in the array. The function should return the index of the element if it is found in the array, and -1 otherwise. You may not use any built-in array search methods (e.g. indexOf, includes) to solv...
7
7
[ { "content": "Write a JavaScript function that creates a 2-dimensional array with the following requirements:\n\n1. The array should have dimensions m x n, where m and n are positive integers.\n2. Each element in the array should be a randomly generated number between 0 and 10000 (inclusive).\n3. The array shou...
[ { "content": "Write a JavaScript function that creates a 2-dimensional array with the following requirements:\n\n1. The array should have dimensions m x n, where m and n are positive integers.\n2. Each element in the array should be a randomly generated number between 0 and 10000 (inclusive).\n3. The array shou...
9
3