gpt-3.5-turbo-0125· openai
from WildChat-4.8M
Write a 10 nodejs usefull code with your imagination
- User
Write a 10 nodejs usefull code with your imagination
- Assistant
- Generate a random number between 1 and 100:
javascriptconst randomNum = Math.floor(Math.random() * 100) + 1; console.log(randomNum);- Check if a given number is even or odd:
javascriptconst checkEvenOdd = (num) => { if(num % 2 === 0){ console.log("Even"); } else { console.log("Odd"); } } checkEvenOdd(5);- Convert a given string to uppercase:
javascriptconst stringToUpper = (str) => { return str.toUpperCase(); } console.log(stringToUpper("hello world"));- Shuffle an array of numbers:
javascriptconst shuffleArray = (arr) => { return arr.sort(() => Math.random() - 0.5); } console.log(shuffleArray([1, 2, 3, 4, 5]));- Calculate the factorial of a number:
javascriptconst factorial = (num) => { if(num === 0 || num === 1){ return 1; } else { return num * factorial(num - 1); } } console.log(factorial(5));- Find the maximum number in an array:
javascriptconst findMax = (arr) => { return Math.max(...arr); } console.log(findMax([4, 2, 7, 1, 9]));- Reverse a string:
javascriptconst reverseString = (str) => { return str.split('').reverse().join(''); } console.log(reverseString("hello world"));- Calculate the sum of all numbers in an array:
javascript
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.