prompt stringlengths 45 9.08k | chosen listlengths 2 2 | rejected listlengths 2 2 | score_chosen int64 6 9 | score_rejected int64 1 4 |
|---|---|---|---|---|
Create a JavaScript function that takes in an array of integers and finds the third smallest distinct number. If there are not enough distinct numbers in the array to find the third smallest, the function should return undefined.
The function should consider negative numbers and zero as well.
For example, given the ... | [
{
"content": "Create a JavaScript function that takes in an array of integers and finds the third smallest distinct number. If there are not enough distinct numbers in the array to find the third smallest, the function should return undefined. \n\nThe function should consider negative numbers and zero as well.\... | [
{
"content": "Create a JavaScript function that takes in an array of integers and finds the third smallest distinct number. If there are not enough distinct numbers in the array to find the third smallest, the function should return undefined. \n\nThe function should consider negative numbers and zero as well.\... | 9 | 2 |
Suggest a way of preserving the order of elements in a JavaScript array using a set data structure, while also achieving a time complexity of O(1) for both insertion and retrieval operations. Additionally, provide a piece of erroneous code that attempts to achieve this but fails to maintain the order of elements.
Fur... | [
{
"content": "Suggest a way of preserving the order of elements in a JavaScript array using a set data structure, while also achieving a time complexity of O(1) for both insertion and retrieval operations. Additionally, provide a piece of erroneous code that attempts to achieve this but fails to maintain the or... | [
{
"content": "Suggest a way of preserving the order of elements in a JavaScript array using a set data structure, while also achieving a time complexity of O(1) for both insertion and retrieval operations. Additionally, provide a piece of erroneous code that attempts to achieve this but fails to maintain the or... | 6 | 3 |
Write a JavaScript program to create an array of the first 1000 Fibonacci numbers that are prime and have a prime index. Additionally, the program should calculate the sum of all the prime Fibonacci numbers in the array. The program should be optimized to have a time complexity of O(n), where n is the index of the larg... | [
{
"content": "Write a JavaScript program to create an array of the first 1000 Fibonacci numbers that are prime and have a prime index. Additionally, the program should calculate the sum of all the prime Fibonacci numbers in the array. The program should be optimized to have a time complexity of O(n), where n is... | [
{
"content": "Write a JavaScript program to create an array of the first 1000 Fibonacci numbers that are prime and have a prime index. Additionally, the program should calculate the sum of all the prime Fibonacci numbers in the array. The program should be optimized to have a time complexity of O(n), where n is... | 7 | 3 |
Write a JavaScript function that generates a random number between 1 and 100. The generated number should not be divisible by any prime number less than or equal to | [
{
"content": "Write a JavaScript function that generates a random number between 1 and 100. The generated number should not be divisible by any prime number less than or equal to ",
"role": "user"
},
{
"content": "Here's a JavaScript function that generates a random number between 1 and 100, excludi... | [
{
"content": "Write a JavaScript function that generates a random number between 1 and 100. The generated number should not be divisible by any prime number less than or equal to ",
"role": "user"
},
{
"content": "Here's a JavaScript function that generates a random number between 1 and 100, excludi... | 7 | 4 |
Using JavaScript, create a function to find the longest word in a string, while ignoring any punctuation marks or special characters. Additionally, the function should return an array containing all the words that have the same length as the longest word. However, you are not allowed to use built-in JavaScript methods ... | [
{
"content": "Using JavaScript, create a function to find the longest word in a string, while ignoring any punctuation marks or special characters. Additionally, the function should return an array containing all the words that have the same length as the longest word. However, you are not allowed to use built-... | [
{
"content": "Using JavaScript, create a function to find the longest word in a string, while ignoring any punctuation marks or special characters. Additionally, the function should return an array containing all the words that have the same length as the longest word. However, you are not allowed to use built-... | 7 | 3 |
Write a JavaScript function that takes an array of numbers and returns the sum of all the numbers in the array. The function should also check if the array is sorted in ascending order and if not, it should sort the array before calculating the sum. Additionally, the function should ignore any negative numbers in the a... | [
{
"content": "Write a JavaScript function that takes an array of numbers and returns the sum of all the numbers in the array. The function should also check if the array is sorted in ascending order and if not, it should sort the array before calculating the sum. Additionally, the function should ignore any neg... | [
{
"content": "Write a JavaScript function that takes an array of numbers and returns the sum of all the numbers in the array. The function should also check if the array is sorted in ascending order and if not, it should sort the array before calculating the sum. Additionally, the function should ignore any neg... | 8 | 2 |
Please write a function that takes in a nested array and returns a flattened version of the array. The function should handle arrays of any depth and size.
Example:
Input:
[1, [2], 3, [4, [5, 6], 7]]
Output:
[1, 2, 3, 4, 5, 6, 7]
Note: Your function should not use any built-in array flattening methods.
Additional ... | [
{
"content": "Please write a function that takes in a nested array and returns a flattened version of the array. The function should handle arrays of any depth and size.\n\nExample:\n\nInput:\n[1, [2], 3, [4, [5, 6], 7]]\n\nOutput:\n[1, 2, 3, 4, 5, 6, 7]\n\nNote: Your function should not use any built-in array ... | [
{
"content": "Please write a function that takes in a nested array and returns a flattened version of the array. The function should handle arrays of any depth and size.\n\nExample:\n\nInput:\n[1, [2], 3, [4, [5, 6], 7]]\n\nOutput:\n[1, 2, 3, 4, 5, 6, 7]\n\nNote: Your function should not use any built-in array ... | 8 | 3 |
Write a JavaScript function that takes two parameters: a starting number and an ending number. The function should return a new array containing the squared values of all odd numbers within the range (inclusive). The function should have a time complexity of O(n), where n is the number of elements in the range.
Additi... | [
{
"content": "Write a JavaScript function that takes two parameters: a starting number and an ending number. The function should return a new array containing the squared values of all odd numbers within the range (inclusive). The function should have a time complexity of O(n), where n is the number of elements... | [
{
"content": "Write a JavaScript function that takes two parameters: a starting number and an ending number. The function should return a new array containing the squared values of all odd numbers within the range (inclusive). The function should have a time complexity of O(n), where n is the number of elements... | 6 | 1 |
Create a JavaScript function that will loop through an array of numbers and calculate the sum of all the elements. However, you are not allowed to use the '+' operator or any built-in functions for addition, and you cannot use any temporary variables. The function should return the sum. The time complexity of the funct... | [
{
"content": "Create a JavaScript function that will loop through an array of numbers and calculate the sum of all the elements. However, you are not allowed to use the '+' operator or any built-in functions for addition, and you cannot use any temporary variables. The function should return the sum. The time c... | [
{
"content": "Create a JavaScript function that will loop through an array of numbers and calculate the sum of all the elements. However, you are not allowed to use the '+' operator or any built-in functions for addition, and you cannot use any temporary variables. The function should return the sum. The time c... | 6 | 2 |
Write a JavaScript function to check if all elements of an array of numbers are distinct and non-negative. The function should also handle arrays that contain both numbers and strings. The function should return true only if all numbers in the array are distinct, greater than or equal to zero, and the sum of all number... | [
{
"content": "Write a JavaScript function to check if all elements of an array of numbers are distinct and non-negative. The function should also handle arrays that contain both numbers and strings. The function should return true only if all numbers in the array are distinct, greater than or equal to zero, and... | [
{
"content": "Write a JavaScript function to check if all elements of an array of numbers are distinct and non-negative. The function should also handle arrays that contain both numbers and strings. The function should return true only if all numbers in the array are distinct, greater than or equal to zero, and... | 9 | 2 |
Create a JavaScript function to format a date object into day, month, and year, while also accounting for different time zones and displaying the date in both 12-hour and 24-hour formats. Additionally, the function should be able to handle dates in different calendars (such as Gregorian, Julian, Hijri, etc.) and conver... | [
{
"content": "Create a JavaScript function to format a date object into day, month, and year, while also accounting for different time zones and displaying the date in both 12-hour and 24-hour formats. Additionally, the function should be able to handle dates in different calendars (such as Gregorian, Julian, H... | [
{
"content": "Create a JavaScript function to format a date object into day, month, and year, while also accounting for different time zones and displaying the date in both 12-hour and 24-hour formats. Additionally, the function should be able to handle dates in different calendars (such as Gregorian, Julian, H... | 9 | 3 |
Create a JavaScript program that takes an array of numbers and returns an object with three properties: "positiveSum", "negativeSum", and "zeroSum".
The "positiveSum" property should represent the sum of the squares of all the unique positive numbers in the array. Duplicate positive numbers should be excluded from th... | [
{
"content": "Create a JavaScript program that takes an array of numbers and returns an object with three properties: \"positiveSum\", \"negativeSum\", and \"zeroSum\". \n\nThe \"positiveSum\" property should represent the sum of the squares of all the unique positive numbers in the array. Duplicate positive nu... | [
{
"content": "Create a JavaScript program that takes an array of numbers and returns an object with three properties: \"positiveSum\", \"negativeSum\", and \"zeroSum\". \n\nThe \"positiveSum\" property should represent the sum of the squares of all the unique positive numbers in the array. Duplicate positive nu... | 7 | 3 |
Create a JavaScript program that calculates the total price of items in a shopping cart, including discounts.
## Requirements:
1. The program should take an array of objects as a parameter. Each object represents an item in the shopping cart and has the following properties:
- name: a string representing the name o... | [
{
"content": "Create a JavaScript program that calculates the total price of items in a shopping cart, including discounts.\n\n## Requirements:\n1. The program should take an array of objects as a parameter. Each object represents an item in the shopping cart and has the following properties:\n - name: a stri... | [
{
"content": "Create a JavaScript program that calculates the total price of items in a shopping cart, including discounts.\n\n## Requirements:\n1. The program should take an array of objects as a parameter. Each object represents an item in the shopping cart and has the following properties:\n - name: a stri... | 9 | 2 |
Write a function in JavaScript that adds a table row to an HTML table, but with the following requirements:
1. The function should take three parameters: the HTML table element, an array of values for each cell in the new row, and an optional callback function.
2. The new row should be added to the end of the table.
3... | [
{
"content": "Write a function in JavaScript that adds a table row to an HTML table, but with the following requirements:\n\n1. The function should take three parameters: the HTML table element, an array of values for each cell in the new row, and an optional callback function.\n2. The new row should be added t... | [
{
"content": "Write a function in JavaScript that adds a table row to an HTML table, but with the following requirements:\n\n1. The function should take three parameters: the HTML table element, an array of values for each cell in the new row, and an optional callback function.\n2. The new row should be added t... | 6 | 4 |
Formulate a query in MongoDB to find records with a specific field having an array containing a certain value. Additionally, the query should only return documents where the array contains the value more than once, and the value itself is not the first or last element in the array. The query should be efficient and sho... | [
{
"content": "Formulate a query in MongoDB to find records with a specific field having an array containing a certain value. Additionally, the query should only return documents where the array contains the value more than once, and the value itself is not the first or last element in the array. The query shoul... | [
{
"content": "Formulate a query in MongoDB to find records with a specific field having an array containing a certain value. Additionally, the query should only return documents where the array contains the value more than once, and the value itself is not the first or last element in the array. The query shoul... | 7 | 1 |
Develop JavaScript code to find the nth Fibonacci number within a time complexity of O(log n), without using any loops or recursion. | [
{
"content": "Develop JavaScript code to find the nth Fibonacci number within a time complexity of O(log n), without using any loops or recursion.",
"role": "user"
},
{
"content": "To find the nth Fibonacci number without using loops or recursion and with a time complexity of O(log n), we can use ma... | [
{
"content": "Develop JavaScript code to find the nth Fibonacci number within a time complexity of O(log n), without using any loops or recursion.",
"role": "user"
},
{
"content": "To find the nth Fibonacci number without using loops or recursion and with a time complexity of O(log n), we can use ma... | 8 | 4 |
Write JavaScript code to print the Fibonacci sequence, but instead of starting with 0 and 1, start with a different pair of numbers provided as input. Additionally, implement a recursive solution to calculate the nth Fibonacci number.
Your code should handle edge cases, such as invalid input (non-numeric values, nega... | [
{
"content": "Write JavaScript code to print the Fibonacci sequence, but instead of starting with 0 and 1, start with a different pair of numbers provided as input. Additionally, implement a recursive solution to calculate the nth Fibonacci number. \n\nYour code should handle edge cases, such as invalid input (... | [
{
"content": "Write JavaScript code to print the Fibonacci sequence, but instead of starting with 0 and 1, start with a different pair of numbers provided as input. Additionally, implement a recursive solution to calculate the nth Fibonacci number. \n\nYour code should handle edge cases, such as invalid input (... | 9 | 3 |
Design a function in JavaScript to find the sum of the first n prime numbers. The function should check if the input is a positive integer and return an error message if it is not. The input should also be validated to ensure that it is within the range of 1 to 1000, inclusive. If the input is out of range, the functio... | [
{
"content": "Design a function in JavaScript to find the sum of the first n prime numbers. The function should check if the input is a positive integer and return an error message if it is not. The input should also be validated to ensure that it is within the range of 1 to 1000, inclusive. If the input is out... | [
{
"content": "Design a function in JavaScript to find the sum of the first n prime numbers. The function should check if the input is a positive integer and return an error message if it is not. The input should also be validated to ensure that it is within the range of 1 to 1000, inclusive. If the input is out... | 6 | 2 |
Using the given array, create a JavaScript function that returns the sum of all elements in the array. The function should only iterate through the array once and must have a time complexity of O(n). Additionally, the function should not use any built-in array methods or operators such as reduce, map, or for loops. The... | [
{
"content": "Using the given array, create a JavaScript function that returns the sum of all elements in the array. The function should only iterate through the array once and must have a time complexity of O(n). Additionally, the function should not use any built-in array methods or operators such as reduce, ... | [
{
"content": "Using the given array, create a JavaScript function that returns the sum of all elements in the array. The function should only iterate through the array once and must have a time complexity of O(n). Additionally, the function should not use any built-in array methods or operators such as reduce, ... | 9 | 4 |
Create a function in JavaScript that takes in an array of numbers and returns the sum of all unique pairs of numbers in the array that add up to a given target number.
The function should have a time complexity of O(n log n), where n is the length of the array. Additionally, the function should not use any built-in Ja... | [
{
"content": "Create a function in JavaScript that takes in an array of numbers and returns the sum of all unique pairs of numbers in the array that add up to a given target number.\n\nThe function should have a time complexity of O(n log n), where n is the length of the array. Additionally, the function should... | [
{
"content": "Create a function in JavaScript that takes in an array of numbers and returns the sum of all unique pairs of numbers in the array that add up to a given target number.\n\nThe function should have a time complexity of O(n log n), where n is the length of the array. Additionally, the function should... | 9 | 4 |
Create a JavaScript function that takes two strings as parameters and checks if the first one contains the second one. The function should be case-sensitive and should return true only if the second string is found as a whole word within the first string. Additionally, the function should handle special characters and ... | [
{
"content": "Create a JavaScript function that takes two strings as parameters and checks if the first one contains the second one. The function should be case-sensitive and should return true only if the second string is found as a whole word within the first string. Additionally, the function should handle s... | [
{
"content": "Create a JavaScript function that takes two strings as parameters and checks if the first one contains the second one. The function should be case-sensitive and should return true only if the second string is found as a whole word within the first string. Additionally, the function should handle s... | 9 | 1 |
Write a JavaScript code to read the content of a given URL, validate its format using regular expressions, and store it in a MongoDB database. The code should also check for the presence of specific keywords within the content and add appropriate tags to the entries in the database. The data should be properly indexed ... | [
{
"content": "Write a JavaScript code to read the content of a given URL, validate its format using regular expressions, and store it in a MongoDB database. The code should also check for the presence of specific keywords within the content and add appropriate tags to the entries in the database. The data shoul... | [
{
"content": "Write a JavaScript code to read the content of a given URL, validate its format using regular expressions, and store it in a MongoDB database. The code should also check for the presence of specific keywords within the content and add appropriate tags to the entries in the database. The data shoul... | 6 | 4 |
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 program should sort the st... | [
{
"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... | 6 | 1 |
How can we remove duplicates from an array in JavaScript without using any built-in array methods, additional data structures, or nested loops, while maintaining the original order of elements and achieving a time complexity of O(n)? | [
{
"content": "How can we remove duplicates from an array in JavaScript without using any built-in array methods, additional data structures, or nested loops, while maintaining the original order of elements and achieving a time complexity of O(n)?",
"role": "user"
},
{
"content": "To remove duplicat... | [
{
"content": "How can we remove duplicates from an array in JavaScript without using any built-in array methods, additional data structures, or nested loops, while maintaining the original order of elements and achieving a time complexity of O(n)?",
"role": "user"
},
{
"content": "To remove duplicat... | 9 | 4 |
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 4. Return the sum of all the subarrays.
let input = [1, 2, 3, 4, 5, 6, 7, 8];
let K = 3;
Example:
Input: input = [1, 2, 3, 4, 5, 6, ... | [
{
"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 4. Return the sum of all the subarrays.\n\nlet input = [1, 2, 3, 4, 5, 6, 7, 8];\nlet K = 3;\n\nExample:\nInput:... | [
{
"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 4. Return the sum of all the subarrays.\n\nlet input = [1, 2, 3, 4, 5, 6, 7, 8];\nlet K = 3;\n\nExample:\nInput:... | 7 | 1 |
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 1000 and less than 9999. Additionally, the controller should validate that the page parameter is provided in the URL and display an error mes... | [
{
"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 1000 and less than 9999. Additionally, the controller should validate that the page parameter is provided in the URL ... | [
{
"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 1000 and less than 9999. Additionally, the controller should validate that the page parameter is provided in the URL ... | 6 | 4 |
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, and it should only use a constant amount of extra space. The time complexity of the function should be O(n), where n is the length o... | [
{
"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, and it should only use a constant amount of extra space. The time complexity of the function should be O(n), w... | [
{
"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, and it should only use a constant amount of extra space. The time complexity of the function should be O(n), w... | 6 | 2 |
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. Additionally, sort the resulting array in ascending order based on the property names. | [
{
"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. Additionally, sort the resulting array in ascending order based on the property names."... | [
{
"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. Additionally, sort the resulting array in ascending order based on the property names."... | 7 | 3 |
Write an algorithm to find the common elements in two arrays. The algorithm should have a time complexity of O(n), where n is the size of the larger array. Additionally, you are not allowed to use any additional data structures, built-in functions, or loops (such as for, while, or do-while) for solving the problem. Ins... | [
{
"content": "Write an algorithm to find the common elements in two arrays. The algorithm should have a time complexity of O(n), where n is the size of the larger array. Additionally, you are not allowed to use any additional data structures, built-in functions, or loops (such as for, while, or do-while) for so... | [
{
"content": "Write an algorithm to find the common elements in two arrays. The algorithm should have a time complexity of O(n), where n is the size of the larger array. Additionally, you are not allowed to use any additional data structures, built-in functions, or loops (such as for, while, or do-while) for so... | 8 | 1 |
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 recursively. Additionally, the ... | [
{
"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 | 2 |
Create a generic function that implements a for-each loop in JavaScript. The function should take an array and a callback function as parameters. It should iterate over each element in the array, but only call the callback function if the element meets a certain condition. The condition should be defined as an addition... | [
{
"content": "Create a generic function that implements a for-each loop in JavaScript. The function should take an array and a callback function as parameters. It should iterate over each element in the array, but only call the callback function if the element meets a certain condition. The condition should be ... | [
{
"content": "Create a generic function that implements a for-each loop in JavaScript. The function should take an array and a callback function as parameters. It should iterate over each element in the array, but only call the callback function if the element meets a certain condition. The condition should be ... | 8 | 4 |
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 time complexity of 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 ... | [
{
"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 ... | 7 | 4 |
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 unique ID, and the JSO... | [
{
"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 ... | 9 | 4 |
Write a JavaScript function to test if two given arrays are equal. The function should 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 have a time complexity of ... | [
{
"content": "Write a JavaScript function to test if two given arrays are equal. The function should 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 have... | [
{
"content": "Write a JavaScript function to test if two given arrays are equal. The function should 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 have... | 9 | 1 |
Implement a RESTful API endpoint that handles the creation and retrieval of a user resource. The API endpoint should use the POST method and accept JSON data in the request body for creation, and GET method for retrieval. The request body for creation should contain the user data in the following format:
```json
{
"... | [
{
"content": "Implement a RESTful API endpoint that handles the creation and retrieval of a user resource. The API endpoint should use the POST method and accept JSON data in the request body for creation, and GET method for retrieval. The request body for creation should contain the user data in the following ... | [
{
"content": "Implement a RESTful API endpoint that handles the creation and retrieval of a user resource. The API endpoint should use the POST method and accept JSON data in the request body for creation, and GET method for retrieval. The request body for creation should contain the user data in the following ... | 6 | 2 |
Write a JavaScript function that takes three arguments: a string representing a color, an array of HTML elements, and a boolean flag. The function should change the background color of each element in the array to the specified color.
The function should also check if the color provided is valid. A valid color is defi... | [
{
"content": "Write a JavaScript function that takes three arguments: a string representing a color, an array of HTML elements, and a boolean flag. 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 vali... | [
{
"content": "Write a JavaScript function that takes three arguments: a string representing a color, an array of HTML elements, and a boolean flag. 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 vali... | 6 | 2 |
Construct an array of 1000 random numbers between -1000 and 1000, without using any built-in JavaScript functions for generating random numbers. Additionally, ensure that none of the generated numbers are duplicates and that the array is sorted in descending order. | [
{
"content": "Construct an array of 1000 random numbers between -1000 and 1000, without using any built-in JavaScript functions for generating random numbers. Additionally, ensure that none of the generated numbers are duplicates and that the array is sorted in descending order.",
"role": "user"
},
{
... | [
{
"content": "Construct an array of 1000 random numbers between -1000 and 1000, without using any built-in JavaScript functions for generating random numbers. Additionally, ensure that none of the generated numbers are duplicates and that the array is sorted in descending order.",
"role": "user"
},
{
... | 9 | 2 |
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 arr2, the second elem... | [
{
"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... | 8 | 4 |
Generate a program in JavaScript to find the longest common substring of two strings. The strings can contain special characters, digits, and whitespace in addition to alphabets. Additionally, the program should be case-sensitive.
str1 = "a@b 1cd"
str2 = "cd ef9g"
# Additional Instructions
1. Implement the solution u... | [
{
"content": "Generate a program in JavaScript to find the longest common substring of two strings. The strings can contain special characters, digits, and whitespace in addition to alphabets. Additionally, the program should be case-sensitive.\n\nstr1 = \"a@b 1cd\"\nstr2 = \"cd ef9g\"\n\n# Additional Instructi... | [
{
"content": "Generate a program in JavaScript to find the longest common substring of two strings. The strings can contain special characters, digits, and whitespace in addition to alphabets. Additionally, the program should be case-sensitive.\n\nstr1 = \"a@b 1cd\"\nstr2 = \"cd ef9g\"\n\n# Additional Instructi... | 6 | 1 |
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. Additionally, if the user holds down the left mouse button for more than 1 second d... | [
{
"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. Additionally, if the user holds down the left mouse button fo... | [
{
"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. Additionally, if the user holds down the left mouse button fo... | 8 | 1 |
Using JavaScript, create an object named "person" with the following properties: "name" (string value of "John"), "age" (number value between 18 and 65), "gender" (string value of either "male" or "female"), "hobbies" (array of at least 3 string values, each with a length between 5 and 10 characters), and "friends" (ar... | [
{
"content": "Using JavaScript, create an object named \"person\" with the following properties: \"name\" (string value of \"John\"), \"age\" (number value between 18 and 65), \"gender\" (string value of either \"male\" or \"female\"), \"hobbies\" (array of at least 3 string values, each with a length between 5... | [
{
"content": "Using JavaScript, create an object named \"person\" with the following properties: \"name\" (string value of \"John\"), \"age\" (number value between 18 and 65), \"gender\" (string value of either \"male\" or \"female\"), \"hobbies\" (array of at least 3 string values, each with a length between 5... | 7 | 1 |
Write a JavaScript function that takes in a string and returns the string with each word reversed, while preserving the punctuation and capitalization of the original string. The function should also include a timestamp of when the string was reversed, in the format "yyyy-mm-dd HH:mm:ss". Additionally, the function sho... | [
{
"content": "Write a JavaScript function that takes in a string and returns the string with each word reversed, while preserving the punctuation and capitalization of the original string. The function should also include a timestamp of when the string was reversed, in the format \"yyyy-mm-dd HH:mm:ss\". Additi... | [
{
"content": "Write a JavaScript function that takes in a string and returns the string with each word reversed, while preserving the punctuation and capitalization of the original string. The function should also include a timestamp of when the string was reversed, in the format \"yyyy-mm-dd HH:mm:ss\". Additi... | 9 | 1 |
Compute the sum of an array using a JavaScript loop, without using any built-in array methods or arithmetic operators (+, -, *, /). Additionally, the sum should only include positive integers in the array. If there are no positive integers in the array, return 0. The input array can contain both positive and negative i... | [
{
"content": "Compute the sum of an array using a JavaScript loop, without using any built-in array methods or arithmetic operators (+, -, *, /). Additionally, the sum should only include positive integers in the array. If there are no positive integers in the array, return 0. The input array can contain both p... | [
{
"content": "Compute the sum of an array using a JavaScript loop, without using any built-in array methods or arithmetic operators (+, -, *, /). Additionally, the sum should only include positive integers in the array. If there are no positive integers in the array, return 0. The input array can contain both p... | 8 | 1 |
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 capitalized. The input string may con... | [
{
"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 | 3 |
Write a JavaScript program to compute the sum of all the prime numbers in the given array. The program should handle negative values and decimals in the input array. The final sum should be rounded to the nearest whole number.
Additionally, the program should ignore any non-numeric values in the input array and only ... | [
{
"content": "Write a JavaScript program to compute the sum of all the prime numbers in the given array. The program should handle negative values and decimals in the input array. The final sum should be rounded to the nearest whole number. \n\nAdditionally, the program should ignore any non-numeric values in t... | [
{
"content": "Write a JavaScript program to compute the sum of all the prime numbers in the given array. The program should handle negative values and decimals in the input array. The final sum should be rounded to the nearest whole number. \n\nAdditionally, the program should ignore any non-numeric values in t... | 7 | 1 |
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 addresses in addition t... | [
{
"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... | 6 | 3 |
Write a JavaScript code snippet that generates a random password with the following criteria:
- The password must be at least 12 characters long.
- It must contain at least two uppercase letters, two lowercase letters, two digits, and two special characters (!@#$%^&*).
- The password should not contain any repeated cha... | [
{
"content": "Write a JavaScript code snippet that generates a random password with the following criteria:\n- The password must be at least 12 characters long.\n- It must contain at least two uppercase letters, two lowercase letters, two digits, and two special characters (!@#$%^&*).\n- The password should not... | [
{
"content": "Write a JavaScript code snippet that generates a random password with the following criteria:\n- The password must be at least 12 characters long.\n- It must contain at least two uppercase letters, two lowercase letters, two digits, and two special characters (!@#$%^&*).\n- The password should not... | 9 | 1 |
Write a script in Node.js to log a message to the console. Additionally, create a function that takes in a parameter and logs a different message based on the value of the parameter. The function should handle both positive and negative values, and log an error message if the parameter is not a number. The script shoul... | [
{
"content": "Write a script in Node.js to log a message to the console. Additionally, create a function that takes in a parameter and logs a different message based on the value of the parameter. The function should handle both positive and negative values, and log an error message if the parameter is not a nu... | [
{
"content": "Write a script in Node.js to log a message to the console. Additionally, create a function that takes in a parameter and logs a different message based on the value of the parameter. The function should handle both positive and negative values, and log an error message if the parameter is not a nu... | 9 | 2 |
Create a function in JavaScript called "printHello" that takes in a number parameter "n" and a string parameter "name". The function should print "Hello [name]" n times using a for loop. However, the function should print "Hello [name]" in reverse order from n to 1. If n is not a positive integer or name is not a valid... | [
{
"content": "Create a function in JavaScript called \"printHello\" that takes in a number parameter \"n\" and a string parameter \"name\". The function should print \"Hello [name]\" n times using a for loop. However, the function should print \"Hello [name]\" in reverse order from n to 1. If n is not a positiv... | [
{
"content": "Create a function in JavaScript called \"printHello\" that takes in a number parameter \"n\" and a string parameter \"name\". The function should print \"Hello [name]\" n times using a for loop. However, the function should print \"Hello [name]\" in reverse order from n to 1. If n is not a positiv... | 8 | 4 |
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. Additionally, the program should only use a single recursive function for finding the minimum, and not make use of any built-in array methods or loops. | [
{
"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. Additionally, the program should only use a single recursive function for finding the minimum, and not make use of any built-in array... | [
{
"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. Additionally, the program should only use a single recursive function for finding the minimum, and not make use of any built-in array... | 7 | 1 |
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 function to calculate ea... | [
{
"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... | 9 | 2 |
Create a function in JavaScript which prints all twin prime numbers up to a given number.
(Note: Twin prime numbers are a pair of prime numbers that differ by 2, for example, (3, 5), (11, 13), (17, 19), etc.)
Additionally, make sure to implement the function using a recursive approach rather than an iterative one.
Y... | [
{
"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... | 8 | 3 |
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 input string when removin... | [
{
"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 | 3 |
Create a for loop structure in JavaScript to iterate through the numbers from 0 to 100 and display only the prime numbers on the console. Additionally, implement a function called isPrime() that takes a number as an argument and returns a boolean value indicating whether the number is prime or not. Use this function in... | [
{
"content": "Create a for loop structure in JavaScript to iterate through the numbers from 0 to 100 and display only the prime numbers on the console. Additionally, implement a function called isPrime() that takes a number as an argument and returns a boolean value indicating whether the number is prime or not... | [
{
"content": "Create a for loop structure in JavaScript to iterate through the numbers from 0 to 100 and display only the prime numbers on the console. Additionally, implement a function called isPrime() that takes a number as an argument and returns a boolean value indicating whether the number is prime or not... | 6 | 1 |
Sort the following array of numbers [7,2,4,1,9] in descending order using JavaScript.
Additional requirements:
- You are not allowed to use any built-in sorting functions or libraries.
- You must implement your own sorting algorithm.
- Your sorting algorithm should have a time complexity of O(n^2).
- Your sorting alg... | [
{
"content": "Sort the following array of numbers [7,2,4,1,9] in descending order using JavaScript. \n\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. \n\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... | 6 | 2 |
Write a JavaScript code snippet to set a value for a cookie, but the cookie must be encrypted using AES encryption algorithm with a randomly generated key and initialization vector (IV) before being stored. The encrypted cookie value should also be base64 encoded. Additionally, the code should include a function to dec... | [
{
"content": "Write a JavaScript code snippet to set a value for a cookie, but the cookie must be encrypted using AES encryption algorithm with a randomly generated key and initialization vector (IV) before being stored. The encrypted cookie value should also be base64 encoded. Additionally, the code should inc... | [
{
"content": "Write a JavaScript code snippet to set a value for a cookie, but the cookie must be encrypted using AES encryption algorithm with a randomly generated key and initialization vector (IV) before being stored. The encrypted cookie value should also be base64 encoded. Additionally, the code should inc... | 9 | 4 |
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). Additionally, you are not allowed to use any loop constructs (e.g., for loop, while loop) to iterate over the characters of the... | [
{
"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). Additionally, you are not allowed to use any loop constructs (e.g., for loop, while loop) to iterate over... | [
{
"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). Additionally, you are not allowed to use any loop constructs (e.g., for loop, while loop) to iterate over... | 8 | 2 |
How do you format a number to two decimal points in JavaScript?
Provide a piece of code that attempts to format a number to two decimal points but produces an incorrect result. Additionally, explain why the code produces the incorrect result and suggest an alternative solution to correctly format the number.
# Erron... | [
{
"content": "How do you format a number to two decimal points in JavaScript? \n\nProvide a piece of code that attempts to format a number to two decimal points but produces an incorrect result. Additionally, explain why the code produces the incorrect result and suggest an alternative solution to correctly for... | [
{
"content": "How do you format a number to two decimal points in JavaScript? \n\nProvide a piece of code that attempts to format a number to two decimal points but produces an incorrect result. Additionally, explain why the code produces the incorrect result and suggest an alternative solution to correctly for... | 6 | 2 |
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 80%. Additionally, the ... | [
{
"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... | 7 | 3 |
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 based on their values, and any nested objects are also deeply cloned. Additionally, the program should exclude any properties that have a value of null, undefined,... | [
{
"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 based on their values, and any nested objects are also deeply cloned. Additionally, the program should exclude any properties that have a val... | [
{
"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 based on their values, and any nested objects are also deeply cloned. Additionally, the program should exclude any properties that have a val... | 7 | 1 |
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 if the navigation fail... | [
{
"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 ... | 6 | 1 |
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. Additionally, the method should have a time complexity of O(n^2) or less, where n is the number of sides of the 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. Additionally, the method should have a time complexity of O(n^2) or less, where n is the number of sides of the... | [
{
"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. Additionally, the method should have a time complexity of O(n^2) or less, where n is the number of sides of the... | 9 | 4 |
Create a JavaScript class for a student that includes properties such as first name, last name, grades for all courses taken, and the number of courses taken. The class should have methods to add a new course with a corresponding grade, calculate the average grade, weighted average grade, highest and lowest grades, and... | [
{
"content": "Create a JavaScript class for a student that includes properties such as first name, last name, grades for all courses taken, and the number of courses taken. The class should have methods to add a new course with a corresponding grade, calculate the average grade, weighted average grade, highest ... | [
{
"content": "Create a JavaScript class for a student that includes properties such as first name, last name, grades for all courses taken, and the number of courses taken. The class should have methods to add a new course with a corresponding grade, calculate the average grade, weighted average grade, highest ... | 8 | 3 |
Create a function in JavaScript to generate an array containing 20 unique prime random numbers between 1 and 10000 (inclusive) in descending order. The function should also return the sum of the generated prime numbers. | [
{
"content": "Create a function in JavaScript to generate an array containing 20 unique prime random numbers between 1 and 10000 (inclusive) in descending order. The function should also return the sum of the generated prime numbers.",
"role": "user"
},
{
"content": "Here is a function that generate... | [
{
"content": "Create a function in JavaScript to generate an array containing 20 unique prime random numbers between 1 and 10000 (inclusive) in descending order. The function should also return the sum of the generated prime numbers.",
"role": "user"
},
{
"content": "Here is a function that generate... | 6 | 4 |
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 student is enrolled in.
Add... | [
{
"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 | 1 |
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 function should return ... | [
{
"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... | 9 | 1 |
Write a JavaScript code to create a function that checks if a given number is divisible by both 2 and 3, and also check if the sum of its digits is divisible by both 5 and 7. | [
{
"content": "Write a JavaScript code to create a function that checks if a given number is divisible by both 2 and 3, and also check if the sum of its digits is divisible by both 5 and 7.",
"role": "user"
},
{
"content": "Here is a JavaScript code that creates a function to check if a given number ... | [
{
"content": "Write a JavaScript code to create a function that checks if a given number is divisible by both 2 and 3, and also check if the sum of its digits is divisible by both 5 and 7.",
"role": "user"
},
{
"content": "Here is a JavaScript code that creates a function to check if a given number ... | 9 | 1 |
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.
The animation should only start when the element is clicked and the animation should only be triggered if the window width is greater than 800 pixels.
Furthermo... | [
{
"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... | 6 | 2 |
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), "score" (number), and "gender" (string).
The function should sort the array of objects based on the following criteria:
1. Sort by the "sco... | [
{
"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), \"score\" (number), and \"gender\" (string).\n\nThe function should sort the array of objects based on the followin... | [
{
"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), \"score\" (number), and \"gender\" (string).\n\nThe function should sort the array of objects based on the followin... | 6 | 1 |
Implement a function in Node.js that takes in a string as input and returns the number of unique words in the string. However, the function should not consider any words that are shorter than 3 characters in length as part of the unique word count. Additionally, the function should be case-insensitive, meaning that wor... | [
{
"content": "Implement a function in Node.js that takes in a string as input and returns the number of unique words in the string. However, the function should not consider any words that are shorter than 3 characters in length as part of the unique word count. Additionally, the function should be case-insensi... | [
{
"content": "Implement a function in Node.js that takes in a string as input and returns the number of unique words in the string. However, the function should not consider any words that are shorter than 3 characters in length as part of the unique word count. Additionally, the function should be case-insensi... | 9 | 2 |
Create a function that takes an array of string elements and sorts them in alphabetical order. However, if the array contains any numbers, the function should place them at the beginning of the sorted array, followed by the sorted strings. Additionally, if the array contains any special characters, the function should ... | [
{
"content": "Create a function that takes an array of string elements and sorts them in alphabetical order. However, if the array contains any numbers, the function should place them at the beginning of the sorted array, followed by the sorted strings. Additionally, if the array contains any special characters... | [
{
"content": "Create a function that takes an array of string elements and sorts them in alphabetical order. However, if the array contains any numbers, the function should place them at the beginning of the sorted array, followed by the sorted strings. Additionally, if the array contains any special characters... | 6 | 4 |
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.
In addition, your implement... | [
{
"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 | 2 |
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 complexity of O(1) for ... | [
{
"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... | 9 | 1 |
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 JavaScript random numb... | [
{
"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 ... | 7 | 2 |
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 sums cannot be compared... | [
{
"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... | 6 | 4 |
Suppose you have an array of numbers like [2,5,3,7] and you have to find the sum of all the prime numbers present in the array. Write a JavaScript program for this.
Please note that the array may contain negative numbers as well.
## Additional Requirements:
1. Your program should handle an empty array and return 0 as... | [
{
"content": "Suppose you have an array of numbers like [2,5,3,7] and you have to find the sum of all the prime numbers present in 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 ... | [
{
"content": "Suppose you have an array of numbers like [2,5,3,7] and you have to find the sum of all the prime numbers present in 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 ... | 9 | 1 |
Write a JavaScript program to simulate a rock, paper, scissors game between 10 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.
Additionally, implement a scoring system that keeps track of the total number of wins and l... | [
{
"content": "Write a JavaScript program to simulate a rock, paper, scissors game between 10 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 to... | [
{
"content": "Write a JavaScript program to simulate a rock, paper, scissors game between 10 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 to... | 9 | 2 |
Construct an array of unique prime integers from 1 to 10000 in ascending order using Javascript. The solution should have a time complexity of O(n log log n) and a space complexity of O(n). | [
{
"content": "Construct an array of unique prime integers from 1 to 10000 in ascending order using Javascript. The solution should have a time complexity of O(n log log n) and a space complexity of O(n).",
"role": "user"
},
{
"content": "To construct an array of unique prime integers from 1 to 10000... | [
{
"content": "Construct an array of unique prime integers from 1 to 10000 in ascending order using Javascript. The solution should have a time complexity of O(n log log n) and a space complexity of O(n).",
"role": "user"
},
{
"content": "To construct an array of unique prime integers from 1 to 10000... | 9 | 1 |
Create a program in JavaScript that calendarizes the upcoming month 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 should also include a val... | [
{
"content": "Create a program in JavaScript that calendarizes the upcoming month 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 sho... | [
{
"content": "Create a program in JavaScript that calendarizes the upcoming month 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 sho... | 6 | 2 |
Convert this temperature from Kelvin to Celsius in JavaScript. The program should round the result to the nearest whole number. The temperature is provided as an input by the user. | [
{
"content": "Convert this temperature from Kelvin to Celsius in JavaScript. The program should round the result to the nearest whole number. The temperature is provided as an input by the user.",
"role": "user"
},
{
"content": "Here's a JavaScript program that converts a temperature from Kelvin to ... | [
{
"content": "Convert this temperature from Kelvin to Celsius in JavaScript. The program should round the result to the nearest whole number. The temperature is provided as an input by the user.",
"role": "user"
},
{
"content": "Here's a JavaScript program that converts a temperature from Kelvin to ... | 9 | 4 |
Write a JavaScript program to find the sum of all prime numbers between two user-entered integers. The program should have a time complexity of O(n^2) and a space complexity of O(1). | [
{
"content": "Write a JavaScript program to find the sum of all prime numbers between two user-entered integers. The program should have a time complexity of O(n^2) and a space complexity of O(1).",
"role": "user"
},
{
"content": "Here's a JavaScript program that finds the sum of all prime numbers b... | [
{
"content": "Write a JavaScript program to find the sum of all prime numbers between two user-entered integers. The program should have a time complexity of O(n^2) and a space complexity of O(1).",
"role": "user"
},
{
"content": "Here's a JavaScript program that finds the sum of all prime numbers b... | 8 | 2 |
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 should handle leap ye... | [
{
"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... | 8 | 4 |
Given an array of numbers, write a JavaScript function to find the maximum number in the array. 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... | [
{
"content": "Given an array of numbers, write a JavaScript function to find the maximum number in the array. 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 ... | [
{
"content": "Given an array of numbers, write a JavaScript function to find the maximum number in the array. 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 ... | 6 | 1 |
Using JavaScript, create a program that prompts the user to enter the number of unique sites they have visited today, which should be a positive integer greater than or equal to 1. Then, prompt the user to enter the name of each unique site visited, which should consist of only alphabetical characters and have a maximu... | [
{
"content": "Using JavaScript, create a program that prompts the user to enter the number of unique sites they have visited today, which should be a positive integer greater than or equal to 1. Then, prompt the user to enter the name of each unique site visited, which should consist of only alphabetical charac... | [
{
"content": "Using JavaScript, create a program that prompts the user to enter the number of unique sites they have visited today, which should be a positive integer greater than or equal to 1. Then, prompt the user to enter the name of each unique site visited, which should consist of only alphabetical charac... | 8 | 3 |
Design a method in JavaScript to validate a password according to the following criteria:
1. The password must contain at least 12 characters.
2. The password must contain at least three uppercase letters.
3. The password must contain at least three lowercase letters.
4. The password must contain at least three numeric... | [
{
"content": "Design a method in JavaScript to validate a password according to the following criteria:\n1. The password must contain at least 12 characters.\n2. The password must contain at least three uppercase letters.\n3. The password must contain at least three lowercase letters.\n4. The password must cont... | [
{
"content": "Design a method in JavaScript to validate a password according to the following criteria:\n1. The password must contain at least 12 characters.\n2. The password must contain at least three uppercase letters.\n3. The password must contain at least three lowercase letters.\n4. The password must cont... | 6 | 4 |
Edit the following JavaScript code to make it able to log only prime numbers. Additionally, optimize the code to have a time complexity of O(n log(log n)).
const myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (let i = 0; i < myArray.length; i++) {
let isPrime = true;
for (let j = 2; j <= Math.sqrt(myArray[i]); j++... | [
{
"content": "Edit the following JavaScript code to make it able to log only prime numbers. Additionally, optimize the code to have a time complexity of O(n log(log n)).\n\nconst myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\nfor (let i = 0; i < myArray.length; i++) {\n let isPrime = true;\n for (let j = 2; j <=... | [
{
"content": "Edit the following JavaScript code to make it able to log only prime numbers. Additionally, optimize the code to have a time complexity of O(n log(log n)).\n\nconst myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\nfor (let i = 0; i < myArray.length; i++) {\n let isPrime = true;\n for (let j = 2; j <=... | 6 | 4 |
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. Additionally, the function should remove any existing inline styles on the pa... | [
{
"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. Additionally, the function should remove any existing i... | [
{
"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. Additionally, the function should remove any existing i... | 8 | 2 |
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. Additionally, you should optimize the algorithm to reduce the number of iterations required to determine if a number is prime. | [
{
"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. Additionally, you should optimize the algorithm to reduce the number of iterations required to determine if a number is pri... | [
{
"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. Additionally, you should optimize the algorithm to reduce the number of iterations required to determine if a number is pri... | 6 | 2 |
Please write a function in JavaScript that takes in an array of numbers and returns the median 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.
You are required to write the function from sc... | [
{
"content": "Please write a function in JavaScript that takes in an array of numbers and returns the median 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 wr... | [
{
"content": "Please write a function in JavaScript that takes in an array of numbers and returns the median 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 wr... | 8 | 1 |
You are given a pre-existing array `arr` and an element `elem`. Write a JavaScript function `insertElement` that inserts `elem` into `arr` at a random index between 0 and the length of `arr` (inclusive), without replacing any existing elements. The random index should be chosen using a built-in random number generator,... | [
{
"content": "You are given a pre-existing array `arr` and an element `elem`. Write a JavaScript function `insertElement` that inserts `elem` into `arr` at a random index between 0 and the length of `arr` (inclusive), without replacing any existing elements. The random index should be chosen using a built-in ra... | [
{
"content": "You are given a pre-existing array `arr` and an element `elem`. Write a JavaScript function `insertElement` that inserts `elem` into `arr` at a random index between 0 and the length of `arr` (inclusive), without replacing any existing elements. The random index should be chosen using a built-in ra... | 8 | 3 |
Write a JavaScript function that takes two parameters: "domain" and "threshold". The function should delete all cookies for the given domain that have an expiration date older than the specified threshold. The function should have a time complexity of O(n), where n is the number of cookies to be deleted. Additionally, ... | [
{
"content": "Write a JavaScript function that takes two parameters: \"domain\" and \"threshold\". The function should delete all cookies for the given domain that have an expiration date older than the specified threshold. The function should have a time complexity of O(n), where n is the number of cookies to ... | [
{
"content": "Write a JavaScript function that takes two parameters: \"domain\" and \"threshold\". The function should delete all cookies for the given domain that have an expiration date older than the specified threshold. The function should have a time complexity of O(n), where n is the number of cookies to ... | 7 | 4 |
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), where n is the length ... | [
{
"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 | 4 |
How to create a new array from an existing array in JavaScript while filtering out all the elements that are divisible by both 2 and 3, and then sorting the remaining elements in descending order? Additionally, you must implement the solution using only tail 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 both 2 and 3, and then sorting the remaining elements in descending order? Additionally, you must implement the solution using only tail recursion and ensure that the original ... | [
{
"content": "How to create a new array from an existing array in JavaScript while filtering out all the elements that are divisible by both 2 and 3, and then sorting the remaining elements in descending order? Additionally, you must implement the solution using only tail recursion and ensure that the original ... | 7 | 4 |
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 the sum of the number... | [
{
"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... | 8 | 2 |
Construct an Express route for handling browser requests for a web page named 'Home'. The route should only be accessible by authenticated users who have specific role permissions, such as 'admin' or 'editor'. Additionally, the route should retrieve data from a remote API, process it using a custom algorithm, and then ... | [
{
"content": "Construct an Express route for handling browser requests for a web page named 'Home'. The route should only be accessible by authenticated users who have specific role permissions, such as 'admin' or 'editor'. Additionally, the route should retrieve data from a remote API, process it using a custo... | [
{
"content": "Construct an Express route for handling browser requests for a web page named 'Home'. The route should only be accessible by authenticated users who have specific role permissions, such as 'admin' or 'editor'. Additionally, the route should retrieve data from a remote API, process it using a custo... | 6 | 3 |
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. Also, add a condition to filter out... | [
{
"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. Also, add a c... | [
{
"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. Also, add a c... | 7 | 3 |
Create a function that identifies the type of a value, but you cannot use any built-in methods or functions to determine the type. You must implement your own logic to determine the type of the value. Additionally, your solution should be able to correctly identify custom data types and their instances. Furthermore, yo... | [
{
"content": "Create a function that identifies the type of a value, but you cannot use any built-in methods or functions to determine the type. You must implement your own logic to determine the type of the value. Additionally, your solution should be able to correctly identify custom data types and their inst... | [
{
"content": "Create a function that identifies the type of a value, but you cannot use any built-in methods or functions to determine the type. You must implement your own logic to determine the type of the value. Additionally, your solution should be able to correctly identify custom data types and their inst... | 7 | 3 |
Suggest an alternate solution to the following JavaScript code.
Given an array of names (length <= 1000) and a maximum length of each name (<= 20), rewrite the above code to use a higher-order function instead of a for loop. The solution should filter out any names that contain special characters and only display name... | [
{
"content": "Suggest an alternate solution to the following JavaScript code.\n\nGiven an array of names (length <= 1000) and a maximum length of each name (<= 20), rewrite the above code to use a higher-order function instead of a for loop. The solution should filter out any names that contain special characte... | [
{
"content": "Suggest an alternate solution to the following JavaScript code.\n\nGiven an array of names (length <= 1000) and a maximum length of each name (<= 20), rewrite the above code to use a higher-order function instead of a for loop. The solution should filter out any names that contain special characte... | 6 | 1 |
Explain the concept of object-oriented programming (OOP) and how it can be implemented with JavaScript. Provide code examples to illustrate the use of classes, inheritance, and polymorphism in JavaScript.
Furthermore, discuss the advantages and disadvantages of using OOP in JavaScript, including its impact on code reu... | [
{
"content": "Explain the concept of object-oriented programming (OOP) and how it can be implemented with JavaScript. Provide code examples to illustrate the use of classes, inheritance, and polymorphism in JavaScript.\n\nFurthermore, discuss the advantages and disadvantages of using OOP in JavaScript, includin... | [
{
"content": "Explain the concept of object-oriented programming (OOP) and how it can be implemented with JavaScript. Provide code examples to illustrate the use of classes, inheritance, and polymorphism in JavaScript.\n\nFurthermore, discuss the advantages and disadvantages of using OOP in JavaScript, includin... | 7 | 2 |
Create a function in JavaScript that converts an input string to its uppercase equivalent 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, punctu... | [
{
"content": "Create a function in JavaScript that converts an input string to its uppercase equivalent 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 alphanume... | [
{
"content": "Create a function in JavaScript that converts an input string to its uppercase equivalent 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 alphanume... | 6 | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.