chosen listlengths 2 2 | rejected listlengths 2 2 | score_chosen int64 6 9 | score_rejected int64 1 9 |
|---|---|---|---|
[
{
"content": "Suggest a function in JavaScript for repeating a given string a specified number of times, but the string must contain only unique characters and the number of times to repeat must be a prime number. Additionally, the function should handle cases where the given string may contain non-alphanumeric... | [
{
"content": "Suggest a function in JavaScript for repeating a given string a specified number of times, but the string must contain only unique characters and the number of times to repeat must be a prime number. Additionally, the function should handle cases where the given string may contain non-alphanumeric... | 7 | 1 |
[
{
"content": "Suggest a loop in JavaScript for traversing an array of objects and printing out specific properties of each object. However, the loop should only print out properties that have a numeric value greater than 10.\n\nAdditional Instructions:\n1. The array of objects should have at least 10 objects.\n... | [
{
"content": "Suggest a loop in JavaScript for traversing an array of objects and printing out specific properties of each object. However, the loop should only print out properties that have a numeric value greater than 10.\n\nAdditional Instructions:\n1. The array of objects should have at least 10 objects.\n... | 9 | 9 |
[
{
"content": "Create a function in JavaScript that takes two parameters: a start number and an end number. The function should return an array of all prime numbers within the given range.\n\nAdditionally, you should implement the Sieve of Eratosthenes algorithm to find the prime numbers efficiently. This algori... | [
{
"content": "Create a function in JavaScript that takes two parameters: a start number and an end number. The function should return an array of all prime numbers within the given range.\n\nAdditionally, you should implement the Sieve of Eratosthenes algorithm to find the prime numbers efficiently. This algori... | 9 | 9 |
[
{
"content": "Write a JavaScript function that takes a string as input and returns the reverse of the string. You are not allowed to use any built-in string reverse function or any other built-in function that directly solves the problem. You should implement your own logic to reverse the string. Your function ... | [
{
"content": "Write a JavaScript function that takes a string as input and returns the reverse of the string. You are not allowed to use any built-in string reverse function or any other built-in function that directly solves the problem. You should implement your own logic to reverse the string. Your function ... | 9 | 9 |
[
{
"content": "Using JavaScript, create a function that takes in an array of numbers as the first argument and a single number as the second argument. The function should return the number from the array that is closest to the second argument, but only if it is larger than the second argument. If there is no num... | [
{
"content": "Using JavaScript, create a function that takes in an array of numbers as the first argument and a single number as the second argument. The function should return the number from the array that is closest to the second argument, but only if it is larger than the second argument. If there is no num... | 8 | 8 |
[
{
"content": "Write a function definition in JavaScript that calculates the factorial of a number. The factorial of a number is the product of all positive integers less than or equal to the number. The function should have a time complexity of O(n) and should not use any built-in JavaScript functions or librar... | [
{
"content": "Write a function definition in JavaScript that calculates the factorial of a number. The factorial of a number is the product of all positive integers less than or equal to the number. The function should have a time complexity of O(n) and should not use any built-in JavaScript functions or librar... | 8 | 8 |
[
{
"content": "Write a JavaScript function that takes two parameters: an array of positive integers and a single positive integer. The function should return an array containing only the elements of the given array that are divisible by the second parameter without any remainder. The function should also remove ... | [
{
"content": "Write a JavaScript function that takes two parameters: an array of positive integers and a single positive integer. The function should return an array containing only the elements of the given array that are divisible by the second parameter without any remainder. The function should also remove ... | 6 | 2 |
[
{
"content": "Create a React component to render a button with a text \"Submit\" that changes to \"Loading...\" when clicked, and disables the button until a response is received from an API call. Display an error message if the API call fails.\n\nAdditionally, implement the following features:\n\n1. Implement ... | [
{
"content": "Create a React component to render a button with a text \"Submit\" that changes to \"Loading...\" when clicked, and disables the button until a response is received from an API call. Display an error message if the API call fails.\n\nAdditionally, implement the following features:\n\n1. Implement ... | 8 | 8 |
[
{
"content": "Write a JavaScript function that takes an array of integers as input and sorts it in ascending order using the Bubble Sort algorithm. The function should have the following additional steps:\n\n1. Initialize a boolean variable \"swapped\" to true.\n2. Create a while loop that continues as long as ... | [
{
"content": "Write a JavaScript function that takes an array of integers as input and sorts it in ascending order using the Bubble Sort algorithm. The function should have the following additional steps:\n\n1. Initialize a boolean variable \"swapped\" to true.\n2. Create a while loop that continues as long as ... | 6 | 2 |
[
{
"content": "Create an array of 10,000 string objects in JavaScript with randomly generated values. Each string value should be a combination of uppercase letters, lowercase letters, and digits, with a length between 5 and 10 characters. Additionally, each string value must contain at least one special charact... | [
{
"content": "Create an array of 10,000 string objects in JavaScript with randomly generated values. Each string value should be a combination of uppercase letters, lowercase letters, and digits, with a length between 5 and 10 characters. Additionally, each string value must contain at least one special charact... | 8 | 8 |
[
{
"content": "Write a JavaScript function that redirects the user to a specific URL after a specified amount of time has passed. The function should take two parameters: the URL to redirect to and the duration in milliseconds. The page should automatically redirect to the specified URL after the specified durat... | [
{
"content": "Write a JavaScript function that redirects the user to a specific URL after a specified amount of time has passed. The function should take two parameters: the URL to redirect to and the duration in milliseconds. The page should automatically redirect to the specified URL after the specified durat... | 6 | 6 |
[
{
"content": "Rewrite the code in JavaScript to remove the first and last characters from a string, while also converting the remaining characters to uppercase and sorting them in reverse alphabetical order. Additionally, handle cases where the string contains numbers or special characters, and make sure the so... | [
{
"content": "Rewrite the code in JavaScript to remove the first and last characters from a string, while also converting the remaining characters to uppercase and sorting them in reverse alphabetical order. Additionally, handle cases where the string contains numbers or special characters, and make sure the so... | 7 | 4 |
[
{
"content": "How to reverse a given string in JavaScript, without using built-in functions or methods, and ensure the code is efficient in terms of time and space complexity?",
"role": "user"
},
{
"content": "To reverse a given string in JavaScript without using built-in functions or methods, and e... | [
{
"content": "How to reverse a given string in JavaScript, without using built-in functions or methods, and ensure the code is efficient in terms of time and space complexity?",
"role": "user"
},
{
"content": "To reverse a given string in JavaScript without using built-in functions or methods, and e... | 9 | 9 |
[
{
"content": "Create a JavaScript function that takes two parameters, an integer and a character, and returns a string with the character repeated that many times. However, if the character is a number, raise an error stating that the character must be a string. If the integer is negative or greater than 10, ra... | [
{
"content": "Create a JavaScript function that takes two parameters, an integer and a character, and returns a string with the character repeated that many times. However, if the character is a number, raise an error stating that the character must be a string. If the integer is negative or greater than 10, ra... | 9 | 9 |
[
{
"content": "Create an array of 20 random integers in JavaScript between -100 and 100. \nAfter creating the array, remove all the duplicates from it. \nThen, sort the array in ascending order. \nFinally, calculate the sum of all the even numbers in the array, ensuring that the solution has a time complexity of... | [
{
"content": "Create an array of 20 random integers in JavaScript between -100 and 100. \nAfter creating the array, remove all the duplicates from it. \nThen, sort the array in ascending order. \nFinally, calculate the sum of all the even numbers in the array, ensuring that the solution has a time complexity of... | 8 | 8 |
[
{
"content": "What is the return type of a Javascript function that returns the sum of two integers and a string concatenation of two strings, while ensuring that the sum of the integers is a prime number and the length of the concatenated string is greater than 10 characters?",
"role": "user"
},
{
... | [
{
"content": "What is the return type of a Javascript function that returns the sum of two integers and a string concatenation of two strings, while ensuring that the sum of the integers is a prime number and the length of the concatenated string is greater than 10 characters?",
"role": "user"
},
{
... | 8 | 8 |
[
{
"content": "Create a JavaScript program to validate an IP address, ensuring that it is a valid IPv4 address, that it is not a private IP address, that it is not a reserved IP address, that it is not a multicast IP address, and that it is not a loopback IP address.",
"role": "user"
},
{
"content": ... | [
{
"content": "Create a JavaScript program to validate an IP address, ensuring that it is a valid IPv4 address, that it is not a private IP address, that it is not a reserved IP address, that it is not a multicast IP address, and that it is not a loopback IP address.",
"role": "user"
},
{
"content": ... | 8 | 3 |
[
{
"content": "Compare two arrays in JavaScript and return true if they have the same elements in the same order, false otherwise. The arrays can contain any type of values, including nested arrays and objects. Additionally, the solution should not use any built-in JavaScript array methods such as 'sort', 'filte... | [
{
"content": "Compare two arrays in JavaScript and return true if they have the same elements in the same order, false otherwise. The arrays can contain any type of values, including nested arrays and objects. Additionally, the solution should not use any built-in JavaScript array methods such as 'sort', 'filte... | 7 | 7 |
[
{
"content": "Create a function in JavaScript to subtract two dates and return the difference in hours, minutes, and seconds, taking into account daylight saving time changes and different time zones.\n\ndate1 = \"2020-11-01 12:30:00\"\ndate2 = \"2020-11-06 10:15:30\"\n\nIn addition, the function should also ha... | [
{
"content": "Create a function in JavaScript to subtract two dates and return the difference in hours, minutes, and seconds, taking into account daylight saving time changes and different time zones.\n\ndate1 = \"2020-11-01 12:30:00\"\ndate2 = \"2020-11-06 10:15:30\"\n\nIn addition, the function should also ha... | 7 | 7 |
[
{
"content": "Create a JavaScript function to calculate the total price of an order, taking into account the following additional requirements:\n- The function should throw an error if any item in the order has a price less than or equal to zero.\n- The function should round the total price to two decimal place... | [
{
"content": "Create a JavaScript function to calculate the total price of an order, taking into account the following additional requirements:\n- The function should throw an error if any item in the order has a price less than or equal to zero.\n- The function should round the total price to two decimal place... | 9 | 9 |
[
{
"content": "Parse the following JSON string and create a JavaScript object. Additionally, add a nested object within the original object with the key \"address\" and the value of another JavaScript object containing the keys \"street\", \"city\", and \"country\". The values for these keys should be \"123 Main... | [
{
"content": "Parse the following JSON string and create a JavaScript object. Additionally, add a nested object within the original object with the key \"address\" and the value of another JavaScript object containing the keys \"street\", \"city\", and \"country\". The values for these keys should be \"123 Main... | 9 | 9 |
[
{
"content": "Read an array of numbers from the user and return the contents in a single comma-separated string in JavaScript. The input array may contain negative numbers and floating-point numbers. The output string should have the numbers formatted to three decimal places. If the array is empty, return an em... | [
{
"content": "Read an array of numbers from the user and return the contents in a single comma-separated string in JavaScript. The input array may contain negative numbers and floating-point numbers. The output string should have the numbers formatted to three decimal places. If the array is empty, return an em... | 8 | 4 |
[
{
"content": "Write a JavaScript code to create an array of prime numbers between 1 and 1000.\n\n#Additional Instructions#\n1. Implement a function called `isPrime` that takes a number as input and returns `true` if the number is prime, and `false` otherwise. You cannot use any built-in JavaScript functions or ... | [
{
"content": "Write a JavaScript code to create an array of prime numbers between 1 and 1000.\n\n#Additional Instructions#\n1. Implement a function called `isPrime` that takes a number as input and returns `true` if the number is prime, and `false` otherwise. You cannot use any built-in JavaScript functions or ... | 9 | 9 |
[
{
"content": "Write a JavaScript callback function that accepts an array of messages as a parameter. The function should randomly select a message from the array and alert it. The function should also keep track of the messages that have already been alerted and ensure that the same message is not alerted twice... | [
{
"content": "Write a JavaScript callback function that accepts an array of messages as a parameter. The function should randomly select a message from the array and alert it. The function should also keep track of the messages that have already been alerted and ensure that the same message is not alerted twice... | 6 | 6 |
[
{
"content": "Create a JavaScript class to generate random numbers within a specific range and with a specific distribution. The class should allow the user to set the minimum and maximum values for the generated numbers, as well as the desired distribution (e.g., normal distribution, exponential distribution, ... | [
{
"content": "Create a JavaScript class to generate random numbers within a specific range and with a specific distribution. The class should allow the user to set the minimum and maximum values for the generated numbers, as well as the desired distribution (e.g., normal distribution, exponential distribution, ... | 6 | 2 |
[
{
"content": "Given an array of integers, write a JavaScript function that returns an object containing the frequencies of each element in the array. The function should also handle arrays with negative numbers and floating-point numbers. The input array can have a maximum length of 10^6 elements. The returned ... | [
{
"content": "Given an array of integers, write a JavaScript function that returns an object containing the frequencies of each element in the array. The function should also handle arrays with negative numbers and floating-point numbers. The input array can have a maximum length of 10^6 elements. The returned ... | 7 | 7 |
[
{
"content": "Write a function in JavaScript to remove all vowels from an input string, while preserving the original case of the letters. The function should have a time complexity of O(n), where n is the length of the input string.",
"role": "user"
},
{
"content": "Here's a function in JavaScript ... | [
{
"content": "Write a function in JavaScript to remove all vowels from an input string, while preserving the original case of the letters. The function should have a time complexity of O(n), where n is the length of the input string.",
"role": "user"
},
{
"content": "Here's a function in JavaScript ... | 6 | 6 |
[
{
"content": "Develop a JavaScript code snippet to find the maximum and minimum numbers in an array, while also ensuring that the array contains only unique values and that the length of the array is at least 5.\nnums = [2, 5, 8, 9, 10]",
"role": "user"
},
{
"content": "Here's a JavaScript code snip... | [
{
"content": "Develop a JavaScript code snippet to find the maximum and minimum numbers in an array, while also ensuring that the array contains only unique values and that the length of the array is at least 5.\nnums = [2, 5, 8, 9, 10]",
"role": "user"
},
{
"content": "Here's a JavaScript code snip... | 8 | 8 |
[
{
"content": "Design a Node.js program that calculates the factorial of a number using recursion and handles large numbers efficiently.\n\nTime Complexity Requirement: The program should have a time complexity of O(n) or better.\n\nSpace Complexity Requirement: The program should have a space complexity of O(1)... | [
{
"content": "Design a Node.js program that calculates the factorial of a number using recursion and handles large numbers efficiently.\n\nTime Complexity Requirement: The program should have a time complexity of O(n) or better.\n\nSpace Complexity Requirement: The program should have a space complexity of O(1)... | 8 | 8 |
[
{
"content": "Write a JavaScript function to find all the even numbers from a given array of integers and return them in descending order.\n\n[3, 12, 17, 24, 4, 10, -8, 5, 2, \"7\", null]\n\nAdditional Requirements:\n1. The function should not modify the original array.\n2. The function should ignore non-intege... | [
{
"content": "Write a JavaScript function to find all the even numbers from a given array of integers and return them in descending order.\n\n[3, 12, 17, 24, 4, 10, -8, 5, 2, \"7\", null]\n\nAdditional Requirements:\n1. The function should not modify the original array.\n2. The function should ignore non-intege... | 8 | 8 |
[
{
"content": "Create a program in JavaScript to remove the duplicate entries in an array, but without using any built-in array methods such as filter, reduce, or splice. Additionally, ensure that the program runs in O(n) time complexity, where n is the length of the array.\narr = [1, 2, 3, 1, 4, 5, 6, 4, 1]",
... | [
{
"content": "Create a program in JavaScript to remove the duplicate entries in an array, but without using any built-in array methods such as filter, reduce, or splice. Additionally, ensure that the program runs in O(n) time complexity, where n is the length of the array.\narr = [1, 2, 3, 1, 4, 5, 6, 4, 1]",
... | 8 | 4 |
[
{
"content": "Write a JavaScript function to randomize the order of elements in an array, ensuring that no two consecutive elements in the randomized array have the same starting letter. If a consecutive pair with the same starting letter is found, swap one of the elements with another randomly chosen element i... | [
{
"content": "Write a JavaScript function to randomize the order of elements in an array, ensuring that no two consecutive elements in the randomized array have the same starting letter. If a consecutive pair with the same starting letter is found, swap one of the elements with another randomly chosen element i... | 6 | 3 |
[
{
"content": "Construct a for loop in JavaScript that adds the values in the given array, but the loop should only iterate over the odd indices of the array. Additionally, you should only use the reduce function to calculate the sum. The final sum should be stored in a variable named \"totalSum\". \n\nYou are n... | [
{
"content": "Construct a for loop in JavaScript that adds the values in the given array, but the loop should only iterate over the odd indices of the array. Additionally, you should only use the reduce function to calculate the sum. The final sum should be stored in a variable named \"totalSum\". \n\nYou are n... | 9 | 9 |
[
{
"content": "Use JavaScript to separate the given array into two arrays, one containing the prime numbers and one containing the composite numbers. The output arrays should be sorted in ascending order.\n\nvar numbers = [1,2,3,4,5,6,7,8,9,10];\n\n#Erroneous Code#\nHere is a piece of erroneous code that can be ... | [
{
"content": "Use JavaScript to separate the given array into two arrays, one containing the prime numbers and one containing the composite numbers. The output arrays should be sorted in ascending order.\n\nvar numbers = [1,2,3,4,5,6,7,8,9,10];\n\n#Erroneous Code#\nHere is a piece of erroneous code that can be ... | 8 | 8 |
[
{
"content": "Create a function in JavaScript that returns the second highest number from the given list. \n\nAdditional Step 1:\nSort the list in descending order.\n\nAdditional Step 2:\nIf the sorted list contains duplicates, remove all duplicate elements except for one.\n\nAdditional Step 3:\nIf the sorted l... | [
{
"content": "Create a function in JavaScript that returns the second highest number from the given list. \n\nAdditional Step 1:\nSort the list in descending order.\n\nAdditional Step 2:\nIf the sorted list contains duplicates, remove all duplicate elements except for one.\n\nAdditional Step 3:\nIf the sorted l... | 7 | 1 |
[
{
"content": "Write a JavaScript function that takes in a date as a parameter and returns the date formatted in the following format: \"Day of the week, Month DD, YYYY\". The input date will always be a valid date.\n\nAdditionally, the function should support localization, meaning it should be able to output th... | [
{
"content": "Write a JavaScript function that takes in a date as a parameter and returns the date formatted in the following format: \"Day of the week, Month DD, YYYY\". The input date will always be a valid date.\n\nAdditionally, the function should support localization, meaning it should be able to output th... | 8 | 8 |
[
{
"content": "Write a function in JavaScript that finds the length of a string, without using any built-in methods or properties specifically designed to find the length of a string. Additionally, the function should only count alphanumeric characters (i.e. letters and numbers) in the string and ignore any spec... | [
{
"content": "Write a function in JavaScript that finds the length of a string, without using any built-in methods or properties specifically designed to find the length of a string. Additionally, the function should only count alphanumeric characters (i.e. letters and numbers) in the string and ignore any spec... | 9 | 9 |
[
{
"content": "Write a JavaScript function that capitalizes the first letter of each word in a given string and also removes any extra spaces between words.\n\n#Difficulties added#\n1. Handle words with mixed case: The function should be able to handle words with mixed case, such as \"JaVaScRiPt\" or \"wEb DeVeL... | [
{
"content": "Write a JavaScript function that capitalizes the first letter of each word in a given string and also removes any extra spaces between words.\n\n#Difficulties added#\n1. Handle words with mixed case: The function should be able to handle words with mixed case, such as \"JaVaScRiPt\" or \"wEb DeVeL... | 6 | 6 |
[
{
"content": "Implement a custom sorting algorithm to sort the following array in ascending order using only bitwise operations in JavaScript. The algorithm should have a time complexity of O(nlogn) and use a constant amount of extra space. The implementation should not use any built-in sorting functions or lib... | [
{
"content": "Implement a custom sorting algorithm to sort the following array in ascending order using only bitwise operations in JavaScript. The algorithm should have a time complexity of O(nlogn) and use a constant amount of extra space. The implementation should not use any built-in sorting functions or lib... | 8 | 2 |
[
{
"content": "Create a function that takes two parameters, an array and an element, and checks if the element exists in the array. The function should return the index of the element if it is found in the array, and -1 otherwise. You may not use any built-in array search methods (e.g. indexOf, includes) to solv... | [
{
"content": "Create a function that takes two parameters, an array and an element, and checks if the element exists in the array. The function should return the index of the element if it is found in the array, and -1 otherwise. You may not use any built-in array search methods (e.g. indexOf, includes) to solv... | 8 | 8 |
[
{
"content": "How would you find the frequency of each character in a string using JavaScript and ignore case sensitivity? Write a function that takes a string as input and returns an object with each character as the key and the frequency as the value. Make sure to ignore case sensitivity.\n\n#Erroneous code r... | [
{
"content": "How would you find the frequency of each character in a string using JavaScript and ignore case sensitivity? Write a function that takes a string as input and returns an object with each character as the key and the frequency as the value. Make sure to ignore case sensitivity.\n\n#Erroneous code r... | 8 | 8 |
[
{
"content": "Create a function to sort an array of objects by the property 'name' in descending order. Additionally, modify the array so that the 'name' property becomes uppercase for each object after sorting. \n\nThe input array will contain at most 1 million objects. Each object will have a 'name' property ... | [
{
"content": "Create a function to sort an array of objects by the property 'name' in descending order. Additionally, modify the array so that the 'name' property becomes uppercase for each object after sorting. \n\nThe input array will contain at most 1 million objects. Each object will have a 'name' property ... | 8 | 8 |
[
{
"content": "Write a JavaScript function that creates a 2-dimensional array with the following requirements:\n\n1. The array should have dimensions m x n, where m and n are positive integers.\n2. Each element in the array should be a randomly generated number between 0 and 1000 (inclusive).\n3. The array shoul... | [
{
"content": "Write a JavaScript function that creates a 2-dimensional array with the following requirements:\n\n1. The array should have dimensions m x n, where m and n are positive integers.\n2. Each element in the array should be a randomly generated number between 0 and 1000 (inclusive).\n3. The array shoul... | 6 | 6 |
[
{
"content": "Formulate a regex expression in JavaScript to verify if a given string contains only numbers and is at least 8 characters long. Additionally, the string must not contain repeating consecutive digits.",
"role": "user"
},
{
"content": "To verify if a given string contains only numbers, i... | [
{
"content": "Formulate a regex expression in JavaScript to verify if a given string contains only numbers and is at least 8 characters long. Additionally, the string must not contain repeating consecutive digits.",
"role": "user"
},
{
"content": "To verify if a given string contains only numbers, i... | 8 | 8 |
[
{
"content": "Write a JavaScript program that generates a random number between 0 and 1000 and checks if it is a prime number. If it is a prime number, log it to the console. If not, generate another random number until a prime number is generated and then log it to the console.\n\nAdditionally, the program sho... | [
{
"content": "Write a JavaScript program that generates a random number between 0 and 1000 and checks if it is a prime number. If it is a prime number, log it to the console. If not, generate another random number until a prime number is generated and then log it to the console.\n\nAdditionally, the program sho... | 6 | 6 |
[
{
"content": "Code a JavaScript function to calculate the area of a rectangle, given its length and width. However, the function should also validate that the length and width are positive integers greater than zero. If either the length or width is not a positive integer, the function should return an error me... | [
{
"content": "Code a JavaScript function to calculate the area of a rectangle, given its length and width. However, the function should also validate that the length and width are positive integers greater than zero. If either the length or width is not a positive integer, the function should return an error me... | 9 | 9 |
[
{
"content": "Create a JavaScript function to merge two given arrays, where one array contains numbers and the other array contains strings. The merged array should alternate between numbers and strings in the same order as they appear in the original arrays. Additionally, the merged array should also include o... | [
{
"content": "Create a JavaScript function to merge two given arrays, where one array contains numbers and the other array contains strings. The merged array should alternate between numbers and strings in the same order as they appear in the original arrays. Additionally, the merged array should also include o... | 7 | 7 |
[
{
"content": "Create a JavaScript function that converts a given number to an array of its prime factors. Additionally, the function should handle input validation and error handling.",
"role": "user"
},
{
"content": "Here's a JavaScript function that converts a given number to an array of its prime... | [
{
"content": "Create a JavaScript function that converts a given number to an array of its prime factors. Additionally, the function should handle input validation and error handling.",
"role": "user"
},
{
"content": "Here's a JavaScript function that converts a given number to an array of its prime... | 8 | 8 |
[
{
"content": "Create a new array in JavaScript given an existing one and a number, but make sure that the new array does not contain any duplicate elements and is sorted in descending order.",
"role": "user"
},
{
"content": "Here's a JavaScript function that takes an existing array and a number as a... | [
{
"content": "Create a new array in JavaScript given an existing one and a number, but make sure that the new array does not contain any duplicate elements and is sorted in descending order.",
"role": "user"
},
{
"content": "Here's a JavaScript function that takes an existing array and a number as a... | 8 | 8 |
[
{
"content": "Write a JavaScript function that takes an array of color codes as input and sets the background color of each element to the respective color code. Additionally, change the text color to white for each element.\n\nExample input: [\"#ffa11f\", \"#00ff00\", \"#0000ff\"]\n\nNote:\n- The function shou... | [
{
"content": "Write a JavaScript function that takes an array of color codes as input and sets the background color of each element to the respective color code. Additionally, change the text color to white for each element.\n\nExample input: [\"#ffa11f\", \"#00ff00\", \"#0000ff\"]\n\nNote:\n- The function shou... | 8 | 1 |
[
{
"content": "Create a JavaScript function for sorting an array of numbers in ascending order using the merge sort algorithm. The time complexity of the sorting function should be O(n log n) and the space complexity should be O(n). Do not use any built-in sorting functions or libraries. Additionally, you are no... | [
{
"content": "Create a JavaScript function for sorting an array of numbers in ascending order using the merge sort algorithm. The time complexity of the sorting function should be O(n log n) and the space complexity should be O(n). Do not use any built-in sorting functions or libraries. Additionally, you are no... | 9 | 9 |
[
{
"content": "Create a function in JavaScript to check if a given number is a prime number. The function should also return the next prime number if the given number is not prime.",
"role": "user"
},
{
"content": "Here's a JavaScript function that checks if a given number is prime and returns the ne... | [
{
"content": "Create a function in JavaScript to check if a given number is a prime number. The function should also return the next prime number if the given number is not prime.",
"role": "user"
},
{
"content": "Here's a JavaScript function that checks if a given number is prime and returns the ne... | 6 | 1 |
[
{
"content": "Create an object with key-value pairs using JavaScript and ensure that all keys are unique, all values are of type string, and all values are in uppercase.",
"role": "user"
},
{
"content": "Here's an example of creating an object with unique keys, string values, and all values in upper... | [
{
"content": "Create an object with key-value pairs using JavaScript and ensure that all keys are unique, all values are of type string, and all values are in uppercase.",
"role": "user"
},
{
"content": "Here's an example of creating an object with unique keys, string values, and all values in upper... | 9 | 9 |
[
{
"content": "Create a JavaScript function that takes an array of numbers as parameter and returns the second smallest prime number in it.\n\n## Requirements ##\n1. The input array may contain positive or negative integers.\n2. The function should handle non-numeric elements in the array by ignoring them.\n3. I... | [
{
"content": "Create a JavaScript function that takes an array of numbers as parameter and returns the second smallest prime number in it.\n\n## Requirements ##\n1. The input array may contain positive or negative integers.\n2. The function should handle non-numeric elements in the array by ignoring them.\n3. I... | 7 | 7 |
[
{
"content": "Write a JavaScript program to find out the day of the week for a given date, taking into account the Julian calendar system. However, you cannot use any built-in date/time functions or libraries in your solution.\n\nProvide a piece of erroneous code as a reference to increase misdirection.",
"... | [
{
"content": "Write a JavaScript program to find out the day of the week for a given date, taking into account the Julian calendar system. However, you cannot use any built-in date/time functions or libraries in your solution.\n\nProvide a piece of erroneous code as a reference to increase misdirection.",
"... | 7 | 7 |
[
{
"content": "Merge the elements of two given arrays into one, while maintaining the order of the elements in each array. The resulting array should have all the elements from the first array followed by all the elements from the second array. You should not use any built-in functions or libraries for merging t... | [
{
"content": "Merge the elements of two given arrays into one, while maintaining the order of the elements in each array. The resulting array should have all the elements from the first array followed by all the elements from the second array. You should not use any built-in functions or libraries for merging t... | 8 | 8 |
[
{
"content": "Given a string variable, write a function to convert it to uppercase without using any built-in string manipulation functions or methods in JavaScript. Additionally, the function should handle special characters and maintain their positions in the converted string.",
"role": "user"
},
{
... | [
{
"content": "Given a string variable, write a function to convert it to uppercase without using any built-in string manipulation functions or methods in JavaScript. Additionally, the function should handle special characters and maintain their positions in the converted string.",
"role": "user"
},
{
... | 7 | 4 |
[
{
"content": "Write a JavaScript function that dynamically creates a button element with the following requirements:\n\n1. The button should have a unique ID generated randomly.\n2. The button should have a class named \"custom-button\".\n3. The button text should be \"Click Me\".\n4. When the button is clicked... | [
{
"content": "Write a JavaScript function that dynamically creates a button element with the following requirements:\n\n1. The button should have a unique ID generated randomly.\n2. The button should have a class named \"custom-button\".\n3. The button text should be \"Click Me\".\n4. When the button is clicked... | 6 | 6 |
[
{
"content": "Create a JavaScript function that takes a sentence as a parameter and replaces all occurrences of a given word with another word. The function should also keep track of the number of replacements made and return it as part of the output.\nInput: sentence (string), word to replace (string), replace... | [
{
"content": "Create a JavaScript function that takes a sentence as a parameter and replaces all occurrences of a given word with another word. The function should also keep track of the number of replacements made and return it as part of the output.\nInput: sentence (string), word to replace (string), replace... | 6 | 2 |
[
{
"content": "Create a JavaScript function to convert a given string to a Base-64 encoded value. The function should only use built-in string manipulation methods and should not utilize any third-party libraries or modules. The input string will always consist of alphanumeric characters and may include special ... | [
{
"content": "Create a JavaScript function to convert a given string to a Base-64 encoded value. The function should only use built-in string manipulation methods and should not utilize any third-party libraries or modules. The input string will always consist of alphanumeric characters and may include special ... | 9 | 1 |
[
{
"content": "Create a function that refreshes a web page until an element with the given ID becomes visible. Additionally, the function should handle scenarios where the element does not exist or is not visible even after refreshing multiple times.\n\nTo accomplish this, the function should have the following ... | [
{
"content": "Create a function that refreshes a web page until an element with the given ID becomes visible. Additionally, the function should handle scenarios where the element does not exist or is not visible even after refreshing multiple times.\n\nTo accomplish this, the function should have the following ... | 9 | 9 |
[
{
"content": "Write a JavaScript program to create a random string of 20 characters, where each character must be a unique lowercase letter or number. The string must not contain any duplicate characters.",
"role": "user"
},
{
"content": "Here is a JavaScript program that generates a random string o... | [
{
"content": "Write a JavaScript program to create a random string of 20 characters, where each character must be a unique lowercase letter or number. The string must not contain any duplicate characters.",
"role": "user"
},
{
"content": "Here is a JavaScript program that generates a random string o... | 9 | 3 |
[
{
"content": "Use the .filter() function to find all even numbers from an array of numbers: [3, 5, 10, 7, 8, 11]. You are not allowed to use the modulus operator (%) to check for evenness. Instead, you should use bitwise operations to determine if a number is even.",
"role": "user"
},
{
"content": "... | [
{
"content": "Use the .filter() function to find all even numbers from an array of numbers: [3, 5, 10, 7, 8, 11]. You are not allowed to use the modulus operator (%) to check for evenness. Instead, you should use bitwise operations to determine if a number is even.",
"role": "user"
},
{
"content": "... | 6 | 6 |
[
{
"content": "Create a JavaScript function that checks if a given string is a palindrome, considering the following rules:\n1. The given string must contain only alphanumeric characters (letters and numbers).\n2. The function should ignore any leading or trailing whitespace characters in the string.\n3. The fun... | [
{
"content": "Create a JavaScript function that checks if a given string is a palindrome, considering the following rules:\n1. The given string must contain only alphanumeric characters (letters and numbers).\n2. The function should ignore any leading or trailing whitespace characters in the string.\n3. The fun... | 8 | 8 |
[
{
"content": "Explain the concept of variable scoping in JavaScript and provide an example code snippet that demonstrates how variable scoping works in different scopes. Additionally, explain the differences between the var, let, and const keywords in terms of variable scoping and provide examples to illustrate... | [
{
"content": "Explain the concept of variable scoping in JavaScript and provide an example code snippet that demonstrates how variable scoping works in different scopes. Additionally, explain the differences between the var, let, and const keywords in terms of variable scoping and provide examples to illustrate... | 6 | 6 |
[
{
"content": "Create a function in JavaScript that takes an array as input and returns a new array containing only the unique values from the original array. The input array can contain both numbers and strings. The function should have a time complexity of O(n) and a space complexity of O(n). Make sure to hand... | [
{
"content": "Create a function in JavaScript that takes an array as input and returns a new array containing only the unique values from the original array. The input array can contain both numbers and strings. The function should have a time complexity of O(n) and a space complexity of O(n). Make sure to hand... | 6 | 6 |
[
{
"content": "Obtain the parameter names from a given JavaScript function, where the function must have at least 3 parameters and the parameter names must be in alphabetical order. The function should also check for duplicate parameter names and return an error if any duplicates are found. Additionally, the fun... | [
{
"content": "Obtain the parameter names from a given JavaScript function, where the function must have at least 3 parameters and the parameter names must be in alphabetical order. The function should also check for duplicate parameter names and return an error if any duplicates are found. Additionally, the fun... | 9 | 9 |
[
{
"content": "Write a JavaScript code snippet that displays the Fibonacci sequence up to the nth term on the webpage, where n is a positive integer provided by the user. However, you are not allowed to use recursion or the formula for calculating Fibonacci numbers. You must implement the Fibonacci sequence usin... | [
{
"content": "Write a JavaScript code snippet that displays the Fibonacci sequence up to the nth term on the webpage, where n is a positive integer provided by the user. However, you are not allowed to use recursion or the formula for calculating Fibonacci numbers. You must implement the Fibonacci sequence usin... | 8 | 8 |
[
{
"content": "Write an HTML form that collects the name, email, address, and phone number of a customer. Additionally, include validation for each field to ensure that the name is at least 2 characters long, the email is in the correct format (e.g. example@example.com), the address is not empty, and the phone n... | [
{
"content": "Write an HTML form that collects the name, email, address, and phone number of a customer. Additionally, include validation for each field to ensure that the name is at least 2 characters long, the email is in the correct format (e.g. example@example.com), the address is not empty, and the phone n... | 7 | 7 |
[
{
"content": "Create a JavaScript code to find the frequency of each unique vowel in a string, excluding any special characters or whitespace. The code should output the result in descending order of character frequency.",
"role": "user"
},
{
"content": "Here's the JavaScript code to find the freque... | [
{
"content": "Create a JavaScript code to find the frequency of each unique vowel in a string, excluding any special characters or whitespace. The code should output the result in descending order of character frequency.",
"role": "user"
},
{
"content": "Here's the JavaScript code to find the freque... | 7 | 7 |
[
{
"content": "Design a MongoDB collection Schema for stores' inventory records. In addition to the basic inventory data, the schema should include fields for tracking the following information:\n1. The date and time the inventory record was created.\n2. The date and time the inventory record was last updated.\n... | [
{
"content": "Design a MongoDB collection Schema for stores' inventory records. In addition to the basic inventory data, the schema should include fields for tracking the following information:\n1. The date and time the inventory record was created.\n2. The date and time the inventory record was last updated.\n... | 9 | 9 |
[
{
"content": "Write a JavaScript program to calculate the area of a triangle with the side lengths a, b, and c, where a, b, and c are inputted by the user. Ensure that the program can handle input of decimal values for the side lengths, and round the final answer to two decimal places.\n\nErroneous Code:\n```\n... | [
{
"content": "Write a JavaScript program to calculate the area of a triangle with the side lengths a, b, and c, where a, b, and c are inputted by the user. Ensure that the program can handle input of decimal values for the side lengths, and round the final answer to two decimal places.\n\nErroneous Code:\n```\n... | 6 | 2 |
[
{
"content": "Write a function in JavaScript that takes in two operands and checks if their values and types are equal or not. The function should return a boolean value indicating the result. You are not allowed to use any built-in comparison operators such as `==` or `===`.",
"role": "user"
},
{
"... | [
{
"content": "Write a function in JavaScript that takes in two operands and checks if their values and types are equal or not. The function should return a boolean value indicating the result. You are not allowed to use any built-in comparison operators such as `==` or `===`.",
"role": "user"
},
{
"... | 9 | 2 |
[
{
"content": "Given a string and an array of strings, write a JavaScript code snippet to check if the string is an anagram of any string in the array. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. \n\nTo solve this problem, you can follow these steps:\n1. Create a f... | [
{
"content": "Given a string and an array of strings, write a JavaScript code snippet to check if the string is an anagram of any string in the array. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. \n\nTo solve this problem, you can follow these steps:\n1. Create a f... | 6 | 4 |
[
{
"content": "Create a JavaScript function to validate if a given string is a valid URL. The function should check if the URL has at least one query parameter, if the domain name is a valid registered domain, and if the URL is using a secure protocol (https).\n\nAdditionally, the function should handle cases wh... | [
{
"content": "Create a JavaScript function to validate if a given string is a valid URL. The function should check if the URL has at least one query parameter, if the domain name is a valid registered domain, and if the URL is using a secure protocol (https).\n\nAdditionally, the function should handle cases wh... | 8 | 3 |
[
{
"content": "Create a JavaScript function for the linear search algorithm that searches for a specific element in an array. The function should take two parameters: the array to be searched and the element to be found. The function should return an array of all the indices where the element is found in the arr... | [
{
"content": "Create a JavaScript function for the linear search algorithm that searches for a specific element in an array. The function should take two parameters: the array to be searched and the element to be found. The function should return an array of all the indices where the element is found in the arr... | 6 | 6 |
[
{
"content": "Write a JavaScript function that takes an argument and determines whether it is even or odd. However, you cannot use the modulus operator (%) or any arithmetic operators (+, -, *, /) to determine the parity of the number.",
"role": "user"
},
{
"content": "Here's a JavaScript function t... | [
{
"content": "Write a JavaScript function that takes an argument and determines whether it is even or odd. However, you cannot use the modulus operator (%) or any arithmetic operators (+, -, *, /) to determine the parity of the number.",
"role": "user"
},
{
"content": "Here's a JavaScript function t... | 7 | 7 |
[
{
"content": "Create a valid JavaScript array of objects containing the four elements \"name\", \"age\", \"gender\", and \"hobbies\". Each object should have a randomly generated name, age between 18 and 60, gender (either \"male\" or \"female\"), and an array of randomly generated hobbies (minimum 1 and maximu... | [
{
"content": "Create a valid JavaScript array of objects containing the four elements \"name\", \"age\", \"gender\", and \"hobbies\". Each object should have a randomly generated name, age between 18 and 60, gender (either \"male\" or \"female\"), and an array of randomly generated hobbies (minimum 1 and maximu... | 6 | 6 |
[
{
"content": "Write a JavaScript function that takes two numbers as parameters and returns their sum. The function should be named \"addNumbers\".\n\nThe function should only accept positive integers as inputs. If the input is not a positive integer, the function should throw an error. \n\nAdditionally, the fun... | [
{
"content": "Write a JavaScript function that takes two numbers as parameters and returns their sum. The function should be named \"addNumbers\".\n\nThe function should only accept positive integers as inputs. If the input is not a positive integer, the function should throw an error. \n\nAdditionally, the fun... | 6 | 3 |
[
{
"content": "Design an HTML form with 2 input fields: name and email, a dropdown field with options for gender, and a submit button. Upon submitting the form, validate the input fields to ensure that:\n1. The name field is not empty, contains only alphabetic characters, and has a maximum length of 50 character... | [
{
"content": "Design an HTML form with 2 input fields: name and email, a dropdown field with options for gender, and a submit button. Upon submitting the form, validate the input fields to ensure that:\n1. The name field is not empty, contains only alphabetic characters, and has a maximum length of 50 character... | 8 | 8 |
[
{
"content": "Write a JavaScript code to set a cookie with the name \"username\" and value \"JohnDoe\" only if the current time is between 9 AM and 5 PM on weekdays (Monday to Friday). Otherwise, display an error message stating \"Cookies can only be set between 9 AM and 5 PM on weekdays\".",
"role": "user"... | [
{
"content": "Write a JavaScript code to set a cookie with the name \"username\" and value \"JohnDoe\" only if the current time is between 9 AM and 5 PM on weekdays (Monday to Friday). Otherwise, display an error message stating \"Cookies can only be set between 9 AM and 5 PM on weekdays\".",
"role": "user"... | 9 | 9 |
[
{
"content": "Find the index of the element \"z\" in the array \"alphabet\" below, and print the index. However, you are not allowed to use any built-in array methods such as indexOf(). Implement your own algorithm to find the index.\n\nlet alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',... | [
{
"content": "Find the index of the element \"z\" in the array \"alphabet\" below, and print the index. However, you are not allowed to use any built-in array methods such as indexOf(). Implement your own algorithm to find the index.\n\nlet alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',... | 8 | 8 |
[
{
"content": "Implement a \"while\" loop in JavaScript that prints all prime numbers between 1 and 1000.",
"role": "user"
},
{
"content": "Here's an implementation of a \"while\" loop in JavaScript that prints all prime numbers between 1 and 1000:\n\n```javascript\nlet number = 2;\n\nwhile (number <... | [
{
"content": "Implement a \"while\" loop in JavaScript that prints all prime numbers between 1 and 1000.",
"role": "user"
},
{
"content": "Here's an implementation of a \"while\" loop in JavaScript that prints all prime numbers between 1 and 1000:\n\n```javascript\nlet number = 2;\n\nwhile (number <... | 6 | 6 |
[
{
"content": "Implement a function in JavaScript that can accurately determine the type of a given variable, including but not limited to primitives, objects, arrays, and functions. The function should be able to handle nested structures and return the precise type for each element within the structure. Additio... | [
{
"content": "Implement a function in JavaScript that can accurately determine the type of a given variable, including but not limited to primitives, objects, arrays, and functions. The function should be able to handle nested structures and return the precise type for each element within the structure. Additio... | 8 | 8 |
[
{
"content": "Write a JavaScript function to get the Nth element from the end of a given array. The array can contain both numbers and strings.\n\nThe function should handle the following cases:\n1. If the array is empty, return null.\n2. If the array length is less than N, return null.\n3. If N is negative, re... | [
{
"content": "Write a JavaScript function to get the Nth element from the end of a given array. The array can contain both numbers and strings.\n\nThe function should handle the following cases:\n1. If the array is empty, return null.\n2. If the array length is less than N, return null.\n3. If N is negative, re... | 9 | 1 |
[
{
"content": "Please implement a binary search algorithm in JavaScript to search for a given element x in a sorted array. The array will contain unique positive integers. Your program should return the index of the element if it is found, or -1 if it is not present in the array.\n\narr = [1, 3, 5, 7, 9, 11, 13,... | [
{
"content": "Please implement a binary search algorithm in JavaScript to search for a given element x in a sorted array. The array will contain unique positive integers. Your program should return the index of the element if it is found, or -1 if it is not present in the array.\n\narr = [1, 3, 5, 7, 9, 11, 13,... | 8 | 1 |
[
{
"content": "Generate a function \"capitalize\" in JavaScript to capitalize the first letter of every word, but exclude the words \"a\", \"an\", \"the\", \"and\", \"but\", \"or\", \"for\", \"nor\", \"on\", \"at\", \"to\", \"from\", and \"by\" from being capitalized. The function should also handle special char... | [
{
"content": "Generate a function \"capitalize\" in JavaScript to capitalize the first letter of every word, but exclude the words \"a\", \"an\", \"the\", \"and\", \"but\", \"or\", \"for\", \"nor\", \"on\", \"at\", \"to\", \"from\", and \"by\" from being capitalized. The function should also handle special char... | 8 | 8 |
[
{
"content": "Write a JavaScript function that returns the first 500 prime numbers greater than 1000.\n\n#Difficulty Increase Reasoning#\nBy increasing the starting point of prime numbers to be greater than 1000, the difficulty of the programming test question is increased. This requires the implementation of a... | [
{
"content": "Write a JavaScript function that returns the first 500 prime numbers greater than 1000.\n\n#Difficulty Increase Reasoning#\nBy increasing the starting point of prime numbers to be greater than 1000, the difficulty of the programming test question is increased. This requires the implementation of a... | 8 | 8 |
[
{
"content": "Suggest code to check if an object has a given property and its value is equal to a specific value. The object can have nested properties and the code should be able to handle multiple levels of nesting.\n\nFor example, consider the following object:\nobject = {\n id: 1,\n name: 'John',\n addre... | [
{
"content": "Suggest code to check if an object has a given property and its value is equal to a specific value. The object can have nested properties and the code should be able to handle multiple levels of nesting.\n\nFor example, consider the following object:\nobject = {\n id: 1,\n name: 'John',\n addre... | 7 | 7 |
[
{
"content": "Write a JavaScript function that calculates the factorial of a given number and returns the result as a string with the thousands separator.\n\nNote: The factorial of a number is the product of all positive integers less than or equal to that number. For example, the factorial of 5 is 5 * 4 * 3 * ... | [
{
"content": "Write a JavaScript function that calculates the factorial of a given number and returns the result as a string with the thousands separator.\n\nNote: The factorial of a number is the product of all positive integers less than or equal to that number. For example, the factorial of 5 is 5 * 4 * 3 * ... | 6 | 2 |
[
{
"content": "Write a JavaScript program to implement the bubble sort algorithm for sorting an array of numbers. The program should also include a function to reverse the sorted array. The array should have a length of at least 5 and at most 100. The program should handle duplicate numbers in the array and sort... | [
{
"content": "Write a JavaScript program to implement the bubble sort algorithm for sorting an array of numbers. The program should also include a function to reverse the sorted array. The array should have a length of at least 5 and at most 100. The program should handle duplicate numbers in the array and sort... | 7 | 7 |
[
{
"content": "Modify the following Javascript code to check if a given number is a twin prime or not. A twin prime is a prime number that is either 3 less or 3 more than another prime number. Additionally, the code should also check if the given number is a perfect square.",
"role": "user"
},
{
"con... | [
{
"content": "Modify the following Javascript code to check if a given number is a twin prime or not. A twin prime is a prime number that is either 3 less or 3 more than another prime number. Additionally, the code should also check if the given number is a perfect square.",
"role": "user"
},
{
"con... | 9 | 9 |
[
{
"content": "Generate a correct JavaScript code to subtract two numbers using bitwise operators. The input numbers can be positive or negative and can have decimal points. The code should handle all possible edge cases and return the correct result.",
"role": "user"
},
{
"content": "JavaScript does... | [
{
"content": "Generate a correct JavaScript code to subtract two numbers using bitwise operators. The input numbers can be positive or negative and can have decimal points. The code should handle all possible edge cases and return the correct result.",
"role": "user"
},
{
"content": "JavaScript does... | 6 | 6 |
[
{
"content": "Create a JavaScript code snippet to check if a given number is a prime number. Your solution should have a time complexity of O(sqrt(n)) and should not use any built-in JavaScript functions or libraries for prime number calculation.",
"role": "user"
},
{
"content": "Here is a JavaScrip... | [
{
"content": "Create a JavaScript code snippet to check if a given number is a prime number. Your solution should have a time complexity of O(sqrt(n)) and should not use any built-in JavaScript functions or libraries for prime number calculation.",
"role": "user"
},
{
"content": "Here is a JavaScrip... | 9 | 9 |
[
{
"content": "Generate an HTML table to display the countries, their population, and the percentage of the world population they make up. The table should be sorted in descending order of population. Additionally, the table should only display countries with a population greater than 1 billion.\n\nThe table sho... | [
{
"content": "Generate an HTML table to display the countries, their population, and the percentage of the world population they make up. The table should be sorted in descending order of population. Additionally, the table should only display countries with a population greater than 1 billion.\n\nThe table sho... | 8 | 4 |
[
{
"content": "Transform the given code into an array of objects in JavaScript, ensuring that each object contains properties for both name and age. Additionally, each name must be a string and each age must be a positive integer. However, you should also validate that the age is within a specific range, such as... | [
{
"content": "Transform the given code into an array of objects in JavaScript, ensuring that each object contains properties for both name and age. Additionally, each name must be a string and each age must be a positive integer. However, you should also validate that the age is within a specific range, such as... | 6 | 6 |
[
{
"content": "Create a JavaScript function which takes a string and returns the longest word in it, excluding any words that contain the letter \"z\". For example, given the string \"This is an example string\", the function should return \"example\".",
"role": "user"
},
{
"content": "Here's a JavaS... | [
{
"content": "Create a JavaScript function which takes a string and returns the longest word in it, excluding any words that contain the letter \"z\". For example, given the string \"This is an example string\", the function should return \"example\".",
"role": "user"
},
{
"content": "Here's a JavaS... | 7 | 4 |
[
{
"content": "Write a function in Javascript to return the k-th highest number in an array, where k is a parameter passed to the function. The function should also handle cases where k is larger than the size of the array. Additionally, the function should return an error if the array contains duplicate numbers... | [
{
"content": "Write a function in Javascript to return the k-th highest number in an array, where k is a parameter passed to the function. The function should also handle cases where k is larger than the size of the array. Additionally, the function should return an error if the array contains duplicate numbers... | 6 | 4 |
[
{
"content": "Write a JavaScript program to group an array of objects based on a property and sum up the values of the grouped objects. Each object in the array will now also have a \"department\" property. Additionally, the program should only sum up the values of objects whose salary is above a certain thresh... | [
{
"content": "Write a JavaScript program to group an array of objects based on a property and sum up the values of the grouped objects. Each object in the array will now also have a \"department\" property. Additionally, the program should only sum up the values of objects whose salary is above a certain thresh... | 7 | 4 |
[
{
"content": "Convert the given if-else statement written in JavaScript to a ternary operator. Additionally, implement an error handling mechanism to display a custom error message if the input value of x is not a number and ensure that x is between 1 and 100.",
"role": "user"
},
{
"content": "```ja... | [
{
"content": "Convert the given if-else statement written in JavaScript to a ternary operator. Additionally, implement an error handling mechanism to display a custom error message if the input value of x is not a number and ensure that x is between 1 and 100.",
"role": "user"
},
{
"content": "```ja... | 6 | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.