messages listlengths 2 2 | instruction stringlengths 14 288 | input stringlengths 0 635 | output stringlengths 1 3.91k |
|---|---|---|---|
[
{
"role": "user",
"content": "Create a Wordpress theme from scratch."
},
{
"role": "assistant",
"content": "Create a new folder for your theme, name it \"mytheme\". Open a text editor and a web browser.\n\nCreate a style.css file in your theme folder. Add all the CSS styles as required to make y... | Create a Wordpress theme from scratch. | Create a new folder for your theme, name it "mytheme". Open a text editor and a web browser.
Create a style.css file in your theme folder. Add all the CSS styles as required to make your theme looks as desired.
Create an index.php file in your theme folder, and add the code to create a basic layout of your theme in H... | |
[
{
"role": "user",
"content": "How would you break down a large problem into smaller pieces?"
},
{
"role": "assistant",
"content": "Breaking down a large problem into smaller pieces is a fundamental step in problem-solving. It can be done by first understanding the overall problem and its require... | How would you break down a large problem into smaller pieces? | Breaking down a large problem into smaller pieces is a fundamental step in problem-solving. It can be done by first understanding the overall problem and its requirements. Then, the problem should be divided into smaller, more manageable chunks, which can then be solved independently. This process should be repeated un... | |
[
{
"role": "user",
"content": "What is the advantage of using linear regression for predicting the output?"
},
{
"role": "assistant",
"content": "The advantage of using linear regression for predicting the output is that it can capture important relationship between input variables and the outcom... | What is the advantage of using linear regression for predicting the output? | The advantage of using linear regression for predicting the output is that it can capture important relationship between input variables and the outcome. It is easy to interpret and explain, can produce easily interpretable results, and can also be used to optimize parameters for a given problem. | |
[
{
"role": "user",
"content": "Create a while loop to print all elements of an array.\n\narr = [1, 2, 3, 4, 5]"
},
{
"role": "assistant",
"content": "i = 0\nwhile i < len(arr):\n print(arr[i])\n i += 1"
}
] | Create a while loop to print all elements of an array. | arr = [1, 2, 3, 4, 5] | i = 0
while i < len(arr):
print(arr[i])
i += 1 |
[
{
"role": "user",
"content": "Determine the best data structure to store the following information.\n\nThe information is a list of people and their corresponding email addresses."
},
{
"role": "assistant",
"content": "The best data structure for storing this information is a dictionary, where t... | Determine the best data structure to store the following information. | The information is a list of people and their corresponding email addresses. | The best data structure for storing this information is a dictionary, where the keys are the names of the people and the values are their email addresses. |
[
{
"role": "user",
"content": "Create a function to detect if two given strings are anagrams or not.\n\nstr1 = 'abc'\nstr2 = 'bac'"
},
{
"role": "assistant",
"content": "def is_anagram(str1, str2):\n word1 = ''.join(sorted(str1))\n word2 = ''.join(sorted(str2))\n if word1 == word2:\n ... | Create a function to detect if two given strings are anagrams or not. | str1 = 'abc'
str2 = 'bac' | def is_anagram(str1, str2):
word1 = ''.join(sorted(str1))
word2 = ''.join(sorted(str2))
if word1 == word2:
return True
return False
result = is_anagram(str1, str2)
print("Is anagram:", result) |
[
{
"role": "user",
"content": "Compile the example program that prints \"Hello, World!\" in C++."
},
{
"role": "assistant",
"content": "g++ -o example example.cpp"
}
] | Compile the example program that prints "Hello, World!" in C++. | g++ -o example example.cpp | |
[
{
"role": "user",
"content": "Console log \"Hello\" seven times in JavaScript."
},
{
"role": "assistant",
"content": "for (let i = 0; i < 7; i++) { \n console.log('Hello'); \n}"
}
] | Console log "Hello" seven times in JavaScript. | for (let i = 0; i < 7; i++) {
console.log('Hello');
} | |
[
{
"role": "user",
"content": "Create a singleton class."
},
{
"role": "assistant",
"content": "class SingletonClass:\n _instance = None\n \n def __new__(self):\n if not self._instance:\n self._instance = super().__new__(self)\n return self._instance\n\n# testing\no... | Create a singleton class. | class SingletonClass:
_instance = None
def __new__(self):
if not self._instance:
self._instance = super().__new__(self)
return self._instance
# testing
obj1 = SingletonClass()
obj2 = SingletonClass()
if obj1 is obj2:
print('obj1 and obj2 are the same instance') | |
[
{
"role": "user",
"content": "Write a SQL query to find all the students with a last name beginning with 'D'."
},
{
"role": "assistant",
"content": "SELECT * \nFROM students \nWHERE last_name LIKE 'D%';"
}
] | Write a SQL query to find all the students with a last name beginning with 'D'. | SELECT *
FROM students
WHERE last_name LIKE 'D%'; | |
[
{
"role": "user",
"content": "Transform the C code into an equivalent Python program.\n\nint main()\n{\n int i, j;\n for (i = 0; i < 3; i++) \n for (j = 0; j < 4; j++)\n printf(\"%d %d\\n\", i, j);\n return 0;\n}"
},
{
"role": "assistant",
"content": "for i in range(3)... | Transform the C code into an equivalent Python program. | int main()
{
int i, j;
for (i = 0; i < 3; i++)
for (j = 0; j < 4; j++)
printf("%d %d\n", i, j);
return 0;
} | for i in range(3):
for j in range(4):
print(i, j) |
[
{
"role": "user",
"content": "Modify the code so that it checks if the number input is an integer or a decimal.\n\nnumber = input(\"Please input a number: \")"
},
{
"role": "assistant",
"content": "number = input(\"Please input a number: \")\n\nif type(number) == int:\n print(\"Input is an in... | Modify the code so that it checks if the number input is an integer or a decimal. | number = input("Please input a number: ") | number = input("Please input a number: ")
if type(number) == int:
print("Input is an integer")
else:
print("Input is a decimal") |
[
{
"role": "user",
"content": "Create a user-defined type in Python to store information about a person."
},
{
"role": "assistant",
"content": "class Person:\n def __init__(self, firstname, lastname, age):\n self.firstname = firstname\n self.lastname = lastname\n self.age ... | Create a user-defined type in Python to store information about a person. | class Person:
def __init__(self, firstname, lastname, age):
self.firstname = firstname
self.lastname = lastname
self.age = age
person1 = Person('John', 'Smith', 25) | |
[
{
"role": "user",
"content": "Use jquery to dynamically select an element of a given HTML form and change its value.\n\nForm element: input with id=\"name\""
},
{
"role": "assistant",
"content": "$(\"#name\").val(\"John Doe\");"
}
] | Use jquery to dynamically select an element of a given HTML form and change its value. | Form element: input with id="name" | $("#name").val("John Doe"); |
[
{
"role": "user",
"content": "Write a code to encrypt a text using a Ceasar cipher"
},
{
"role": "assistant",
"content": "def ceasar_cipher(plaintext, shift): \n ciphertext = \"\" \n for i in range(len(plaintext)): \n char = plaintext[i] \n if (char.isupper()): \n ... | Write a code to encrypt a text using a Ceasar cipher | def ceasar_cipher(plaintext, shift):
ciphertext = ""
for i in range(len(plaintext)):
char = plaintext[i]
if (char.isupper()):
ciphertext += chr((ord(char) + shift - 65) % 26 + 65)
else:
ciphertext += chr((ord(char) + shift - 97) % 26 + 97)
return ciphert... | |
[
{
"role": "user",
"content": "We need to find all unique combinations of elements from a given list of items.\n\n[1, 2, 3, 4]"
},
{
"role": "assistant",
"content": "def find_unique_combinations(items):\n result = []\n for i in range(1, len(items) + 1):\n for combination in itertools.combinations... | We need to find all unique combinations of elements from a given list of items. | [1, 2, 3, 4] | def find_unique_combinations(items):
result = []
for i in range(1, len(items) + 1):
for combination in itertools.combinations(items, i):
result.append(list(combination))
return result |
[
{
"role": "user",
"content": "Create a Python program that generates a random number between 0 and 10 and checks if the generated number is even."
},
{
"role": "assistant",
"content": "import random\n\nnum = random.randint(0, 10)\n\nif (num % 2 == 0):\n print(str(num) + \" is even.\")\nelse:\... | Create a Python program that generates a random number between 0 and 10 and checks if the generated number is even. | import random
num = random.randint(0, 10)
if (num % 2 == 0):
print(str(num) + " is even.")
else:
print(str(num) + " is odd.") | |
[
{
"role": "user",
"content": "Edit this code so it can classify whether a number is even or odd.\n\ndef classify_number(num):"
},
{
"role": "assistant",
"content": "def classify_number(num):\n if num % 2 == 0:\n return \"even\"\n else:\n return \"odd\""
}
] | Edit this code so it can classify whether a number is even or odd. | def classify_number(num): | def classify_number(num):
if num % 2 == 0:
return "even"
else:
return "odd" |
[
{
"role": "user",
"content": "Write a Python function to calculate the sum of the series 1^2 + 2^2 + 3^2 + ... + n^2.\n\nn = 8"
},
{
"role": "assistant",
"content": "def sum_series(n):\n sum = 0 \n for num in range(1, n + 1):\n sum += num**2\n return sum"
}
] | Write a Python function to calculate the sum of the series 1^2 + 2^2 + 3^2 + ... + n^2. | n = 8 | def sum_series(n):
sum = 0
for num in range(1, n + 1):
sum += num**2
return sum |
[
{
"role": "user",
"content": "Construct a query in SQL to group records by some value.\n\nTable: \n\n+-----------+-----------+\n| Item | Category |\n+-----------+-----------+\n| Pencil | Office |\n| Phone | Electronics|\n| Pen | Office |\n| Monitor | Electronics|\n+-----------+---... | Construct a query in SQL to group records by some value. | Table:
+-----------+-----------+
| Item | Category |
+-----------+-----------+
| Pencil | Office |
| Phone | Electronics|
| Pen | Office |
| Monitor | Electronics|
+-----------+-----------+ | SELECT Item, Category
FROM table
GROUP BY Category; |
[
{
"role": "user",
"content": "EDIT this JavaScript function to return a list of the square roots of all numbers in a given input array.\n\nfunction squareRoots(arr) {\n // EDIT THIS\n}"
},
{
"role": "assistant",
"content": "function squareRoots(arr) {\n const result = [];\n for (let ele of ar... | EDIT this JavaScript function to return a list of the square roots of all numbers in a given input array. | function squareRoots(arr) {
// EDIT THIS
} | function squareRoots(arr) {
const result = [];
for (let ele of arr) {
result.push(Math.sqrt(ele));
}
return result;
} |
[
{
"role": "user",
"content": "Write an SQL query to find all books with the author's name 'J.K. Rowling'."
},
{
"role": "assistant",
"content": "SELECT * FROM library\nWHERE author = 'J.K. Rowling';"
}
] | Write an SQL query to find all books with the author's name 'J.K. Rowling'. | SELECT * FROM library
WHERE author = 'J.K. Rowling'; | |
[
{
"role": "user",
"content": "Create a procedure in PostgreSQL to delete a table\n\nTable name: Employees"
},
{
"role": "assistant",
"content": "CREATE OR REPLACE PROCEDURE delete_employees_table()\nAS\nBEGIN\n DROP TABLE Employees;\nEND;"
}
] | Create a procedure in PostgreSQL to delete a table | Table name: Employees | CREATE OR REPLACE PROCEDURE delete_employees_table()
AS
BEGIN
DROP TABLE Employees;
END; |
[
{
"role": "user",
"content": "Build a PHP function to check if two strings are anagrams.\n\n$s1 = 'abcd';\n$s2 = 'dcba';"
},
{
"role": "assistant",
"content": "function is_anagram($s1, $s2) { \n // If the lengths of the strings are not equal,\n // they cannot be anagrams\n if (strlen($s... | Build a PHP function to check if two strings are anagrams. | $s1 = 'abcd';
$s2 = 'dcba'; | function is_anagram($s1, $s2) {
// If the lengths of the strings are not equal,
// they cannot be anagrams
if (strlen($s1) != strlen($s2)) {
return false;
}
// Create an array and assign value 0 to each character
$count = array();
for ($i = 0; $i < strlen($s1); $i++) {
... |
[
{
"role": "user",
"content": "Explain the purpose of a web browser."
},
{
"role": "assistant",
"content": "A web browser is a software application used to retrieve, render and traverse information on the World Wide Web. It uses Hypertext Transfer Protocol (HTTP) to request pages from from web se... | Explain the purpose of a web browser. | A web browser is a software application used to retrieve, render and traverse information on the World Wide Web. It uses Hypertext Transfer Protocol (HTTP) to request pages from from web servers, receive them, and display them in an organised way on our device. It also provides tools to allow users to traverse the web ... | |
[
{
"role": "user",
"content": "Write an expression to verify the validity of a given password in Python."
},
{
"role": "assistant",
"content": "import re \n \ndef check(password): \n \n #Define pattern rules\n pattern = r\"^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{8,}\"\n \n if ... | Write an expression to verify the validity of a given password in Python. | import re
def check(password):
#Define pattern rules
pattern = r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}"
if (re.search(pattern,password)):
return True
else:
return False
# Driver code
password = "Geronimo1"
if (check(password)):
print("Valid Password... | |
[
{
"role": "user",
"content": "Given a number n, print “Hello” n times.\n\nn = 5"
},
{
"role": "assistant",
"content": "def print_hello(n):\n for i in range (n):\n print(\"Hello\")\n\nprint_hello(5)\n\nOutput: \nHello \nHello \nHello \nHello \nHello"
}
] | Given a number n, print “Hello” n times. | n = 5 | def print_hello(n):
for i in range (n):
print("Hello")
print_hello(5)
Output:
Hello
Hello
Hello
Hello
Hello |
[
{
"role": "user",
"content": "Write a Java code to encrypt a password using `sha1` hash.\n\nString password = \"password123\";"
},
{
"role": "assistant",
"content": "String hash = MessageDigest.getInstance(\"SHA-1\").digest(password.getBytes(StandardCharsets.UTF_8));"
}
] | Write a Java code to encrypt a password using `sha1` hash. | String password = "password123"; | String hash = MessageDigest.getInstance("SHA-1").digest(password.getBytes(StandardCharsets.UTF_8)); |
[
{
"role": "user",
"content": "Arrange the following characters in a valid Python expression.\n\n<, 1, %, ("
},
{
"role": "assistant",
"content": "(1 % <)"
}
] | Arrange the following characters in a valid Python expression. | <, 1, %, ( | (1 % <) |
[
{
"role": "user",
"content": "Write a query in PostgreSQL for deleting a table."
},
{
"role": "assistant",
"content": "DROP TABLE table_name;"
}
] | Write a query in PostgreSQL for deleting a table. | DROP TABLE table_name; | |
[
{
"role": "user",
"content": "Write an SQL statement to get the top 5 most expensive movies from an inventory table."
},
{
"role": "assistant",
"content": "SELECT title, price\nFROM inventory\nORDER BY price DESC\nLIMIT 5;"
}
] | Write an SQL statement to get the top 5 most expensive movies from an inventory table. | SELECT title, price
FROM inventory
ORDER BY price DESC
LIMIT 5; | |
[
{
"role": "user",
"content": "Construct a loop that prints the characters of the given string in reverse order.\n\nstring = 'Hello World'"
},
{
"role": "assistant",
"content": "for i in range(len(string)-1, -1, -1): \n print(string[i], end=\"\")"
}
] | Construct a loop that prints the characters of the given string in reverse order. | string = 'Hello World' | for i in range(len(string)-1, -1, -1):
print(string[i], end="") |
[
{
"role": "user",
"content": "Describe how to debug a HTML web page."
},
{
"role": "assistant",
"content": "Debugging a HTML page involves inspecting the page elements to detect any errors and identify the source of any issues. Many web browsers have a Developer Tools feature that can be used to... | Describe how to debug a HTML web page. | Debugging a HTML page involves inspecting the page elements to detect any errors and identify the source of any issues. Many web browsers have a Developer Tools feature that can be used to inspect and debug the page. It allows you to view the page HTML and JavaScript, as well as view any errors and warning messages tha... | |
[
{
"role": "user",
"content": "Write a C# program to remove all adjacent duplicates from a string.\n\nstring str = \"azxxzy\";"
},
{
"role": "assistant",
"content": "string removeAdjacentDuplicates(string str) \n{ \n int l = str.Length; \n char[] array = str.ToCharArray(); \n \n int ind... | Write a C# program to remove all adjacent duplicates from a string. | string str = "azxxzy"; | string removeAdjacentDuplicates(string str)
{
int l = str.Length;
char[] array = str.ToCharArray();
int index = 0;
for (int i = 0; i < l; i++)
{
if (i == 0 || array[i - 1] != array[i])
array[index++] = array[i];
else
while (i + 1 < l && array[i + 1... |
[
{
"role": "user",
"content": "Create a regex expression that captures a valid URL."
},
{
"role": "assistant",
"content": "^(https?:\\/\\/)([\\da-zA-Z\\.-]+)\\.([a-zA-Z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$"
}
] | Create a regex expression that captures a valid URL. | ^(https?:\/\/)([\da-zA-Z\.-]+)\.([a-zA-Z\.]{2,6})([\/\w \.-]*)*\/?$ | |
[
{
"role": "user",
"content": "From a given list of words, create a new list with only the words that contain the letter 'a'.\n\nmy_list = [\"cat\", \"dog\", \"apple\", \"pear\"]"
},
{
"role": "assistant",
"content": "new_list = [word for word in my_list if \"a\" in word] # Output: [\"cat\", \"ap... | From a given list of words, create a new list with only the words that contain the letter 'a'. | my_list = ["cat", "dog", "apple", "pear"] | new_list = [word for word in my_list if "a" in word] # Output: ["cat", "apple", "pear"] |
[
{
"role": "user",
"content": "Create an array in JavaScript of objects, each with a name key and a value of a random number."
},
{
"role": "assistant",
"content": "let array = [];\n\nfor (let i = 0; i < 10; i++) {\n let randomNumber = Math.floor(Math.random() * 100);\n let obj = { name: `e... | Create an array in JavaScript of objects, each with a name key and a value of a random number. | let array = [];
for (let i = 0; i < 10; i++) {
let randomNumber = Math.floor(Math.random() * 100);
let obj = { name: `element ${i + 1}`, value: randomNumber };
array.push(obj);
}
console.log(array); | |
[
{
"role": "user",
"content": "Convert the given string to a number in JavaScript.\n\nString: \"42\""
},
{
"role": "assistant",
"content": "Using the parseInt() built-in method, the given string can be converted to a number in JavaScript.\n\nExample:\n\nlet str = \"42\"; \nlet num = parseInt(str)... | Convert the given string to a number in JavaScript. | String: "42" | Using the parseInt() built-in method, the given string can be converted to a number in JavaScript.
Example:
let str = "42";
let num = parseInt(str);
console.log("Number:", num);
// Output: Number: 42 |
[
{
"role": "user",
"content": "Construct an algorithm to fulfill the following purpose\n\nFind the two numbers that add up to a given number N."
},
{
"role": "assistant",
"content": "def twoSum(N, arr):\n for i in range(len(arr)):\n for j in range(i+1, len(arr)):\n if arr[i] ... | Construct an algorithm to fulfill the following purpose | Find the two numbers that add up to a given number N. | def twoSum(N, arr):
for i in range(len(arr)):
for j in range(i+1, len(arr)):
if arr[i] + arr[j] == N:
return (arr[i], arr[j]) |
[
{
"role": "user",
"content": "Write a Ruby program to check for the existence of a given value in an array.\n\nGiven array: [1,2,3,4,5], value to be checked: 3"
},
{
"role": "assistant",
"content": "arr = [1,2,3,4,5]\n\nif arr.include?(3)\n puts 'Value 3 present in the array.'\nend"
}
] | Write a Ruby program to check for the existence of a given value in an array. | Given array: [1,2,3,4,5], value to be checked: 3 | arr = [1,2,3,4,5]
if arr.include?(3)
puts 'Value 3 present in the array.'
end |
[
{
"role": "user",
"content": "Write a gem in Ruby to display the current time"
},
{
"role": "assistant",
"content": "require \"time\"\n\nmodule TimeNow\n def self.display_time\n puts Time.now\n end\nend\n\nTimeNow.display_time"
}
] | Write a gem in Ruby to display the current time | require "time"
module TimeNow
def self.display_time
puts Time.now
end
end
TimeNow.display_time | |
[
{
"role": "user",
"content": "Write a Python code to create two empty lists."
},
{
"role": "assistant",
"content": "list_one = []\nlist_two = []"
}
] | Write a Python code to create two empty lists. | list_one = []
list_two = [] | |
[
{
"role": "user",
"content": "Write an SQL query to find the maximum number of orders for each state.\n\nOrders (id, customer_id, state, order_num)"
},
{
"role": "assistant",
"content": "SELECT state, MAX(order_num) FROM Orders GROUP BY state;"
}
] | Write an SQL query to find the maximum number of orders for each state. | Orders (id, customer_id, state, order_num) | SELECT state, MAX(order_num) FROM Orders GROUP BY state; |
[
{
"role": "user",
"content": "Construct a regular expression to match strings containing only alphabets."
},
{
"role": "assistant",
"content": "/^[a-zA-Z]+$/"
}
] | Construct a regular expression to match strings containing only alphabets. | /^[a-zA-Z]+$/ | |
[
{
"role": "user",
"content": "Print the following string in HTML.\n\n\"Welcome to my website!\""
},
{
"role": "assistant",
"content": "<html>\n <head>\n <title>Welcome to my website!</title>\n </head>\n <body>Welcome to my website!</body>\n</html>"
}
] | Print the following string in HTML. | "Welcome to my website!" | <html>
<head>
<title>Welcome to my website!</title>
</head>
<body>Welcome to my website!</body>
</html> |
[
{
"role": "user",
"content": "Using the provided list of numbers, compute the average\n\n[1, 4, 7, 10]"
},
{
"role": "assistant",
"content": "def calculate_average(numbers):\n return sum(numbers) / len(numbers)"
}
] | Using the provided list of numbers, compute the average | [1, 4, 7, 10] | def calculate_average(numbers):
return sum(numbers) / len(numbers) |
[
{
"role": "user",
"content": "Rewrite the following piece of code in Python.\n\nfor (i = 0; i < 10; i++)\n if (i % 2 == 0)\n printf(\"%d\", i);"
},
{
"role": "assistant",
"content": "for i in range(10):\n if i % 2 == 0:\n print(i)"
}
] | Rewrite the following piece of code in Python. | for (i = 0; i < 10; i++)
if (i % 2 == 0)
printf("%d", i); | for i in range(10):
if i % 2 == 0:
print(i) |
[
{
"role": "user",
"content": "Write a CSS code to display a page element with a border-radius of 5px on all sides."
},
{
"role": "assistant",
"content": ".page-element {\n border-radius: 5px;\n}"
}
] | Write a CSS code to display a page element with a border-radius of 5px on all sides. | .page-element {
border-radius: 5px;
} | |
[
{
"role": "user",
"content": "Design an algorithm for sorting data in ascending order using selection sort."
},
{
"role": "assistant",
"content": "def selection_sort(arr):\n\n for i in range(len(arr)):\n min_index = i\n for j in range(i+1, len(arr)):\n if arr[min_inde... | Design an algorithm for sorting data in ascending order using selection sort. | def selection_sort(arr):
for i in range(len(arr)):
min_index = i
for j in range(i+1, len(arr)):
if arr[min_index] > arr[j]:
min_index = j
arr[i], arr[min_index] = arr[min_index], arr[i]
return arr | |
[
{
"role": "user",
"content": "Sort a given matrix such that the elements in each row are in increasing order.\n\n[[9, 2, 7], [5, 1, 6], [3, 8, 4]]"
},
{
"role": "assistant",
"content": "[[2, 7, 9], [1, 5, 6], [3, 4, 8]]"
}
] | Sort a given matrix such that the elements in each row are in increasing order. | [[9, 2, 7], [5, 1, 6], [3, 8, 4]] | [[2, 7, 9], [1, 5, 6], [3, 4, 8]] |
[
{
"role": "user",
"content": "Swap the values of the two given numbers using a temporary variable.\n\na = 1\nb = 2"
},
{
"role": "assistant",
"content": "temp = a \na = b\nb = temp"
}
] | Swap the values of the two given numbers using a temporary variable. | a = 1
b = 2 | temp = a
a = b
b = temp |
[
{
"role": "user",
"content": "Design an algorithm to add two given binary numbers"
},
{
"role": "assistant",
"content": "def add_binary(b1, b2):\n # initalize result\n result = \"\"\n carry = 0\n # iterate over the bits\n for i in range(max(len(b1), len(b2))):\n a = int(b1[... | Design an algorithm to add two given binary numbers | def add_binary(b1, b2):
# initalize result
result = ""
carry = 0
# iterate over the bits
for i in range(max(len(b1), len(b2))):
a = int(b1[-i-1]) if i < len(b1) else 0
b = int(b2[-i-1]) if i < len(b2) else 0
#calculate sum
sum = carry ^ a ^ b
result = str(sum)... | |
[
{
"role": "user",
"content": "Create a HTML page with a fixed header bar and a scrolling content area."
},
{
"role": "assistant",
"content": "<html> \n <head> \n </head> \n <body> \n <div id=\"header\">\n <!-- header content -->\n </div> \n <div id=\"content\" style=... | Create a HTML page with a fixed header bar and a scrolling content area. | <html>
<head>
</head>
<body>
<div id="header">
<!-- header content -->
</div>
<div id="content" style="overflow-y:scroll;">
<!-- content here -->
</div>
</body>
</html> | |
[
{
"role": "user",
"content": "Check whether all elements in the array are equal using Python.\n\narr = [2,2,2]"
},
{
"role": "assistant",
"content": "# Check whether all elements in the array are equal\nif all(x == arr[0] for x in arr):\n print(\"All elements are equal\")\nelse:\n print(\"... | Check whether all elements in the array are equal using Python. | arr = [2,2,2] | # Check whether all elements in the array are equal
if all(x == arr[0] for x in arr):
print("All elements are equal")
else:
print("Elements are not equal") |
[
{
"role": "user",
"content": "Create a JavaScript function to merge two variables into a single object.\n\nvar a = {name: 'John', age: 21};\nvar b = {surname: 'Doe', gender: 'male'};"
},
{
"role": "assistant",
"content": "function merge(a, b) { \n return Object.assign({}, a, b); \n}\nlet result... | Create a JavaScript function to merge two variables into a single object. | var a = {name: 'John', age: 21};
var b = {surname: 'Doe', gender: 'male'}; | function merge(a, b) {
return Object.assign({}, a, b);
}
let result = merge(a, b);
console.log(result); // {name: 'John', age: 21, surname: 'Doe', gender: 'male'} |
[
{
"role": "user",
"content": "How can we use the set() method to find the unique elements in a given list of integers in C#?"
},
{
"role": "assistant",
"content": "var listOfIntegers = [1,2,3,3,2,2,3];\n\nvar uniqueElements = new HashSet<int>(listOfIntegers);\nforeach (var element in uniqueEleme... | How can we use the set() method to find the unique elements in a given list of integers in C#? | var listOfIntegers = [1,2,3,3,2,2,3];
var uniqueElements = new HashSet<int>(listOfIntegers);
foreach (var element in uniqueElements)
{
Console.WriteLine(element);
} | |
[
{
"role": "user",
"content": "Populate an array with numbers from 1 to 10 in Python."
},
{
"role": "assistant",
"content": "arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
}
] | Populate an array with numbers from 1 to 10 in Python. | arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
[
{
"role": "user",
"content": "Create an HTML page that contains the following table.\n\n<table>\n <tr>\n <th>Name</th>\n <th>Age</th>\n <th>City</th>\n </tr>\n <tr>\n <td>John Doe</td>\n <td>23</td>\n <td>New York</td>\n </tr>\n <tr>\n <td>Trish Smith</td>\n <td>29</td>\n <td... | Create an HTML page that contains the following table. | <table>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>John Doe</td>
<td>23</td>
<td>New York</td>
</tr>
<tr>
<td>Trish Smith</td>
<td>29</td>
<td>Philadelphia</td>
</tr>
</table> | <html>
<head>
<title>Table Sample</title>
</head>
<body>
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>John Doe</td>
<td>23</td>
<td>New York</td>
</tr>
<tr>
<td>Trish Smith</td>
<td>29</td>
<td>Philadelphia</td>
</... |
[
{
"role": "user",
"content": "Create a JavaScript function to filter an array of strings.\n\nstrings = [\"apple\", \"banana\", \"coconut\", \"dragon fruit\"]"
},
{
"role": "assistant",
"content": "function filterStrings(strings) {\n return strings.filter(string => string.length < 7);\n}"
}
] | Create a JavaScript function to filter an array of strings. | strings = ["apple", "banana", "coconut", "dragon fruit"] | function filterStrings(strings) {
return strings.filter(string => string.length < 7);
} |
[
{
"role": "user",
"content": "Generate an array of random integers between 1 and 50 inclusive."
},
{
"role": "assistant",
"content": "let randomIntegersArray = [];\nfor (let i = 0; i < 50; i++) {\n randomIntegersArray.push(Math.floor(Math.random() * (50 - 1 + 1)) + 1);\n}"
}
] | Generate an array of random integers between 1 and 50 inclusive. | let randomIntegersArray = [];
for (let i = 0; i < 50; i++) {
randomIntegersArray.push(Math.floor(Math.random() * (50 - 1 + 1)) + 1);
} | |
[
{
"role": "user",
"content": "Create a function in Node.js that prints out the numbers between 0 and a given limit.\n\nlimit = 10"
},
{
"role": "assistant",
"content": "\"\"\"\nCreate a function in Node.js that prints out the numbers between 0 and a given limit.\n\"\"\"\nfunction printNumbers(li... | Create a function in Node.js that prints out the numbers between 0 and a given limit. | limit = 10 | """
Create a function in Node.js that prints out the numbers between 0 and a given limit.
"""
function printNumbers(limit){
for(let i = 0; i <= limit; i++) {
console.log(i);
}
}
printNumbers(10); |
[
{
"role": "user",
"content": "Validate the email address using a regular expression.\n\nemail = \"example@gmail.com\""
},
{
"role": "assistant",
"content": "import re\n\n# Validate the email address using the regex\nemail_pattern = re.compile(r'\\S+@\\S+\\.\\S+')\nemail_valid = re.match(email_pa... | Validate the email address using a regular expression. | email = "example@gmail.com" | import re
# Validate the email address using the regex
email_pattern = re.compile(r'\S+@\S+\.\S+')
email_valid = re.match(email_pattern, email)
if email_valid:
print("Valid Email Address")
else:
print("Invalid Email Address")
# Output
Valid Email Address |
[
{
"role": "user",
"content": "Edit the following CSS code to add a color of your choice to the <h1> element."
},
{
"role": "assistant",
"content": "h1 {\n color: #FF0000;\n}"
}
] | Edit the following CSS code to add a color of your choice to the <h1> element. | h1 {
color: #FF0000;
} | |
[
{
"role": "user",
"content": "Implement a Java code to print the first 10 multiples of a given number"
},
{
"role": "assistant",
"content": "public class Multiples \n{ \n public static void main(String[] args) \n { \n int number = 5; \n for (int i = 1; i <= 10; i++) \n ... | Implement a Java code to print the first 10 multiples of a given number | public class Multiples
{
public static void main(String[] args)
{
int number = 5;
for (int i = 1; i <= 10; i++)
{
System.out.println(number*i);
}
}
} | |
[
{
"role": "user",
"content": "Explain how to use selectors and filters in CSS."
},
{
"role": "assistant",
"content": "Selectors are used to target specific elements in an HTML document, while filters are used to apply style rules to these elements. Selectors are identified by their attribute lik... | Explain how to use selectors and filters in CSS. | Selectors are used to target specific elements in an HTML document, while filters are used to apply style rules to these elements. Selectors are identified by their attribute like ids, classes, and tags, while filters are indicated by attributes such as color, font size, and display type. Selectors commonly utilize com... | |
[
{
"role": "user",
"content": "Write a script in JavaScript for reversing an array."
},
{
"role": "assistant",
"content": "const reverseArray = arr => \n arr.slice().reverse();"
}
] | Write a script in JavaScript for reversing an array. | const reverseArray = arr =>
arr.slice().reverse(); | |
[
{
"role": "user",
"content": "Design a class to represent a string with length 20 characters"
},
{
"role": "assistant",
"content": "public class String20 { \n private String str;\n private int length;\n\n public String20(String str) \n { \n this.length = 20;\n this.str = str.... | Design a class to represent a string with length 20 characters | public class String20 {
private String str;
private int length;
public String20(String str)
{
this.length = 20;
this.str = str.length()<=length ? str : str.substring(0, length);
}
} | |
[
{
"role": "user",
"content": "Calculate the maximum of three numbers in Java.\n\nint a = 10; \nint b = 15;\nint c = 20;"
},
{
"role": "assistant",
"content": "int max = Math.max(a, Math.max(b, c));\nSystem.out.println(\"Maximum of the three numbers is: \"+max);"
}
] | Calculate the maximum of three numbers in Java. | int a = 10;
int b = 15;
int c = 20; | int max = Math.max(a, Math.max(b, c));
System.out.println("Maximum of the three numbers is: "+max); |
[
{
"role": "user",
"content": "Generate a SQL query to select all distinct numbers from a column named 'nums'"
},
{
"role": "assistant",
"content": "SELECT DISTINCT nums FROM table;"
}
] | Generate a SQL query to select all distinct numbers from a column named 'nums' | SELECT DISTINCT nums FROM table; | |
[
{
"role": "user",
"content": "Generate a unique 6 character alphanumeric string."
},
{
"role": "assistant",
"content": "j4xdu6."
}
] | Generate a unique 6 character alphanumeric string. | j4xdu6. | |
[
{
"role": "user",
"content": "What does the acronym \"CSS\" stand for?"
},
{
"role": "assistant",
"content": "CSS stands for \"Cascading Style Sheets\", which is a style sheet language used for describing the presentation of a webpage written in HTML or XML."
}
] | What does the acronym "CSS" stand for? | CSS stands for "Cascading Style Sheets", which is a style sheet language used for describing the presentation of a webpage written in HTML or XML. | |
[
{
"role": "user",
"content": "Construct a code segment to find all unique characters in a given string.\n\nString: Geeksforgeeks"
},
{
"role": "assistant",
"content": "def find_unique(string): \n uniq_char = [] \n for i in string: \n if i not in uniq_char: \n uniq_char.ap... | Construct a code segment to find all unique characters in a given string. | String: Geeksforgeeks | def find_unique(string):
uniq_char = []
for i in string:
if i not in uniq_char:
uniq_char.append(i)
return uniq_char
print(find_unique("Geeksforgeeks")) |
[
{
"role": "user",
"content": "Generate a random sample with size n from a given pandas DataFrame."
},
{
"role": "assistant",
"content": "import pandas as pd\n\ndef sample_df(df,n):\n return df.sample(n)"
}
] | Generate a random sample with size n from a given pandas DataFrame. | import pandas as pd
def sample_df(df,n):
return df.sample(n) | |
[
{
"role": "user",
"content": "Construct a JavaScript program that displays the current date and time."
},
{
"role": "assistant",
"content": "let date = new Date();\ndocument.write(date);"
}
] | Construct a JavaScript program that displays the current date and time. | let date = new Date();
document.write(date); | |
[
{
"role": "user",
"content": "Write an R statement to calculate the probability of getting a number greater than 5 from a range of 1 to 10."
},
{
"role": "assistant",
"content": "# Calculate the probability\nprobability = mean(x > 5)\n\nprint(f\"Probability of getting a number greater than 5 fro... | Write an R statement to calculate the probability of getting a number greater than 5 from a range of 1 to 10. | # Calculate the probability
probability = mean(x > 5)
print(f"Probability of getting a number greater than 5 from a range of 1 to 10 is {probability}.") | |
[
{
"role": "user",
"content": "Create a virtual machine using Terraform."
},
{
"role": "assistant",
"content": "resource \"azurerm_resource_group\" \"example\" {\n name = \"example-resources\"\n location = \"westus2\"\n}\n\nresource \"azurerm_virtual_machine\" \"example\" {\n name ... | Create a virtual machine using Terraform. | resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "westus2"
}
resource "azurerm_virtual_machine" "example" {
name = "example-vm"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
... | |
[
{
"role": "user",
"content": "Edit the following code to generate a list of the vowels in a given string."
},
{
"role": "assistant",
"content": "def get_vowels(str):\n vowels = ['a', 'e', 'i', 'o', 'u']\n res = []\n for letter in str:\n if letter.lower() in vowels:\n r... | Edit the following code to generate a list of the vowels in a given string. | def get_vowels(str):
vowels = ['a', 'e', 'i', 'o', 'u']
res = []
for letter in str:
if letter.lower() in vowels:
res.append(letter)
return res | |
[
{
"role": "user",
"content": "Using a given array of numbers, create a function to display the frequency of each number."
},
{
"role": "assistant",
"content": "def frequency(array):\n count = {}\n # Count the number of occurances\n for element in array:\n if element not in count:... | Using a given array of numbers, create a function to display the frequency of each number. | def frequency(array):
count = {}
# Count the number of occurances
for element in array:
if element not in count:
count[element] = 1
else:
count[element] += 1
# Display the count
for element in count:
print("Number {} occurs {} times".format(element, c... | |
[
{
"role": "user",
"content": "Write a code that computes the sum and difference of two numbers in JavaScript.\n\nvar x = 10;\nvar y = 5;"
},
{
"role": "assistant",
"content": "var x = 10;\nvar y = 5;\n\nvar sum = x + y;\nvar diff = x - y;\n\nconsole.log(\"The sum of \" + x + \" and \" + y + \" i... | Write a code that computes the sum and difference of two numbers in JavaScript. | var x = 10;
var y = 5; | var x = 10;
var y = 5;
var sum = x + y;
var diff = x - y;
console.log("The sum of " + x + " and " + y + " is: " + sum);
console.log("The difference of " + x + " and " + y + " is: " + diff); |
[
{
"role": "user",
"content": "What would be the JavaScript code to remove duplicate values from an array?\n\n[1, 2, 3, 4, 4, 2, 5]"
},
{
"role": "assistant",
"content": "const inputArray = [1, 2, 3, 4, 4, 2, 5];\n\nconst outputArray = inputArray.filter((arrayVal, indexVal) => {\n return inputAr... | What would be the JavaScript code to remove duplicate values from an array? | [1, 2, 3, 4, 4, 2, 5] | const inputArray = [1, 2, 3, 4, 4, 2, 5];
const outputArray = inputArray.filter((arrayVal, indexVal) => {
return inputArray.indexOf(arrayVal) === indexVal;
});
console.log(outputArray); // [1, 2, 3, 4, 5] |
[
{
"role": "user",
"content": "Given a dataframe, write a function to add a new column that contains the results of a calculation between two columns.\n\ndataframe = Pandas DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]], columns=['A', 'B', 'C'])"
},
{
"role": "assistant",
"content": "def add_calcula... | Given a dataframe, write a function to add a new column that contains the results of a calculation between two columns. | dataframe = Pandas DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]], columns=['A', 'B', 'C']) | def add_calculation_column(dataframe, calculation, column_name):
dataframe[column_name] = dataframe.eval(calculation)
return dataframe |
[
{
"role": "user",
"content": "Edit the following code to insert a new item at the end of a given Python list.\n\nitems = [1, 2, 3]\nnew_item = 4"
},
{
"role": "assistant",
"content": "items = [1, 2, 3] + [new_item]\nprint(items) # prints [1, 2, 3, 4]"
}
] | Edit the following code to insert a new item at the end of a given Python list. | items = [1, 2, 3]
new_item = 4 | items = [1, 2, 3] + [new_item]
print(items) # prints [1, 2, 3, 4] |
[
{
"role": "user",
"content": "Write a C# program to take a given number and print it in words.\n\nint n = 1234"
},
{
"role": "assistant",
"content": "int n = 1234;\nString[] ones = {\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\"};\nString[] tee... | Write a C# program to take a given number and print it in words. | int n = 1234 | int n = 1234;
String[] ones = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
String[] teens = {"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
String[] tens = {"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", ... |
[
{
"role": "user",
"content": "Create a class to represent a blog post in Python."
},
{
"role": "assistant",
"content": "class BlogPost:\n def __init__(self, title, content, author):\n self.title = title\n self.content = content\n self.author = author\n\n def edit_post(... | Create a class to represent a blog post in Python. | class BlogPost:
def __init__(self, title, content, author):
self.title = title
self.content = content
self.author = author
def edit_post(self, new_title, new_content):
self.title = new_title
self.content = new_content | |
[
{
"role": "user",
"content": "Analyze the syntax of the sentence\n\nThis sentence is an example of an imperative statement"
},
{
"role": "assistant",
"content": "This sentence is an example of an imperative statement, which is an order or command given to someone to do something. The subject of ... | Analyze the syntax of the sentence | This sentence is an example of an imperative statement | This sentence is an example of an imperative statement, which is an order or command given to someone to do something. The subject of the imperative sentence, "This sentence", is in the third person and the verb, "is", is in the present tense. |
[
{
"role": "user",
"content": "Write a SQL query to select the top 3 highest salaries in a employees table."
},
{
"role": "assistant",
"content": "SELECT TOP 3 salary FROM employees ORDER BY salary DESC;"
}
] | Write a SQL query to select the top 3 highest salaries in a employees table. | SELECT TOP 3 salary FROM employees ORDER BY salary DESC; | |
[
{
"role": "user",
"content": "Generate a C code snippet to print a given string with a width of 20 characters.\n\nHello"
},
{
"role": "assistant",
"content": "#include <stdio.h> \n#include <string.h> \n \nint main(){ \n char str[20] = \"Hello\"; \n printf(\"%-20s\\n\", str); \n return ... | Generate a C code snippet to print a given string with a width of 20 characters. | Hello | #include <stdio.h>
#include <string.h>
int main(){
char str[20] = "Hello";
printf("%-20s\n", str);
return 0;
} |
[
{
"role": "user",
"content": "Create a HTML page with a table containing five columns and four rows."
},
{
"role": "assistant",
"content": "<html>\n<head>\n <title>Table with Columns and Rows</title>\n</head>\n<body>\n <table>\n <tr>\n <th>Column 1</th>\n <th>Column 2</t... | Create a HTML page with a table containing five columns and four rows. | <html>
<head>
<title>Table with Columns and Rows</title>
</head>
<body>
<table>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Ce... | |
[
{
"role": "user",
"content": "How do you retrieve data from a database using PHP?"
},
{
"role": "assistant",
"content": "Retrieving data from a database using PHP is relatively simple. You can use the PDO (PHP Data Objects) or MySQLi (MySQL Improved) extensions to connect to a database. You can ... | How do you retrieve data from a database using PHP? | Retrieving data from a database using PHP is relatively simple. You can use the PDO (PHP Data Objects) or MySQLi (MySQL Improved) extensions to connect to a database. You can then use an SQL query, such as SELECT, to retrieve data from the database. | |
[
{
"role": "user",
"content": "Create a function in Python that takes two list of strings as parameters and returns a third list of strings which are the elements common in both lists.\n\nlist1 = [\"apple\", \"orange\", \"banana\", \"cherry\"] \nlist2 = [\"apple\", \"grapes\", \"banana\", \"watermelon\"]"
... | Create a function in Python that takes two list of strings as parameters and returns a third list of strings which are the elements common in both lists. | list1 = ["apple", "orange", "banana", "cherry"]
list2 = ["apple", "grapes", "banana", "watermelon"] | def common(list1, list2):
ans_list = []
for i in list1:
for j in list2:
if i == j:
ans_list.append(i)
return ans_list
if __name__ == "__main__":
list1 = ["apple", "orange", "banana", "cherry"]
list2 = ["apple", "grapes", "banana", "watermelon"]
... |
[
{
"role": "user",
"content": "Design a method in JavaScript to validate a password according to certain criteria."
},
{
"role": "assistant",
"content": "function validatePassword(password) {\n const regx = /^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{6,20}$/;\n if (password.match(regx)) {\... | Design a method in JavaScript to validate a password according to certain criteria. | function validatePassword(password) {
const regx = /^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{6,20}$/;
if (password.match(regx)) {
return true;
} else {
return false;
};
} | |
[
{
"role": "user",
"content": "Complete the following code to print a 2D array passed as parameter.\n\ndef print2Dlist (list) :"
},
{
"role": "assistant",
"content": "def print2Dlist (list) :\n\tfor row in list:\n\t\tfor element in row:\n\t\t\tprint (element, end=\" \") \n\t\tprint ()"
}
] | Complete the following code to print a 2D array passed as parameter. | def print2Dlist (list) : | def print2Dlist (list) :
for row in list:
for element in row:
print (element, end=" ")
print () |
[
{
"role": "user",
"content": "Write a Java program to find the 10 numbers closest to the given number.\n\n50"
},
{
"role": "assistant",
"content": "import java.util.Arrays; \n\nclass CloseNumber { \n \n // function to find 10 numbers closest to x \n static void closeNums(int x, int arr[... | Write a Java program to find the 10 numbers closest to the given number. | 50 | import java.util.Arrays;
class CloseNumber {
// function to find 10 numbers closest to x
static void closeNums(int x, int arr[], int n)
{
// array which stores 10 numbers
// closest to x
int result[] = new int[10];
int index = 0;
// initialize differ... |
[
{
"role": "user",
"content": "Design a function that takes two parameters a and two and returns the result of a multiplied by two"
},
{
"role": "assistant",
"content": "def mul_two(a, b):\n return a * b\n\nif __name__ == '__main__':\n x = int(input('Enter first number: '))\n y = int(inp... | Design a function that takes two parameters a and two and returns the result of a multiplied by two | def mul_two(a, b):
return a * b
if __name__ == '__main__':
x = int(input('Enter first number: '))
y = int(input('Enter second number: '))
print(mul_two(x, y)) | |
[
{
"role": "user",
"content": "Create a regex pattern that can match the pattern \"www.somedomain.com/posts/[post_id]\"."
},
{
"role": "assistant",
"content": "^www\\.somedomain\\.com\\/posts\\/\\d+$"
}
] | Create a regex pattern that can match the pattern "www.somedomain.com/posts/[post_id]". | ^www\.somedomain\.com\/posts\/\d+$ | |
[
{
"role": "user",
"content": "Suggest a SQL query to retrieve the employee records with an age greater than 30."
},
{
"role": "assistant",
"content": "SELECT * FROM employees WHERE age > 30;"
}
] | Suggest a SQL query to retrieve the employee records with an age greater than 30. | SELECT * FROM employees WHERE age > 30; | |
[
{
"role": "user",
"content": "Create an SQL query to get the second highest salary from a table named 'empployee'"
},
{
"role": "assistant",
"content": "SELECT MAX(salary) AS second_highest_salary \nFROM employee\nWHERE salary < (SELECT MAX(salary) FROM employee);"
}
] | Create an SQL query to get the second highest salary from a table named 'empployee' | SELECT MAX(salary) AS second_highest_salary
FROM employee
WHERE salary < (SELECT MAX(salary) FROM employee); | |
[
{
"role": "user",
"content": "Write a sample program that performs text classification"
},
{
"role": "assistant",
"content": "import pandas as pd\nimport numpy as np\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn.linear_model import LogisticRegression\n\n# load datase... | Write a sample program that performs text classification | import pandas as pd
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
# load dataset
dataframe = pd.read_csv('text_classification_data.csv')
# convert to vectors
vectorizer = TfidfVectorizer()
vectors = vectorizer.fit_transform(dataframe... | |
[
{
"role": "user",
"content": "Create a function in JavaScript that takes a string as an argument and returns the number of times that string is repeated in the input string.\n\nstring = \"HelloHello\""
},
{
"role": "assistant",
"content": "function countString(str) {\n let count = 0;\n for (le... | Create a function in JavaScript that takes a string as an argument and returns the number of times that string is repeated in the input string. | string = "HelloHello" | function countString(str) {
let count = 0;
for (let i = 0; i < str.length; i++) {
if (str.substring(i, i + 5) == "Hello") {
count++;
}
}
return count;
} |
[
{
"role": "user",
"content": "Create an android app with a search feature.\n\nSearch bar: Top of the app"
},
{
"role": "assistant",
"content": "SearchView searchView = findViewById(R.id.search_field); //Find search field\nsearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {\n... | Create an android app with a search feature. | Search bar: Top of the app | SearchView searchView = findViewById(R.id.search_field); //Find search field
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
//Enter your search logics
return false;
}
@Override
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.