Spaces:
Running
Running
| [ | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Function to add two numbers", | |
| "code": "function add(a, b) {\n return a + b;\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Function to find maximum in array", | |
| "code": "function findMax(arr) {\n return Math.max(...arr);\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Function to reverse a string", | |
| "code": "function reverseString(str) {\n return str.split('').reverse().join('');\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Async function to fetch data from API", | |
| "code": "async function fetchData(url) {\n try {\n const response = await fetch(url);\n if (!response.ok) throw new Error('Network error');\n return await response.json();\n } catch (error) {\n console.error('Fetch error:', error);\n throw error;\n }\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Class with constructor and methods", | |
| "code": "class Person {\n constructor(name, age) {\n this.name = name;\n this.age = age;\n }\n \n greet() {\n return `Hello, I'm ${this.name} and I'm ${this.age} years old`;\n }\n \n isAdult() {\n return this.age >= 18;\n }\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Function to filter array by condition", | |
| "code": "function filterEven(numbers) {\n return numbers.filter(num => num % 2 === 0);\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Function to calculate average of array", | |
| "code": "function calculateAverage(numbers) {\n if (numbers.length === 0) return 0;\n const sum = numbers.reduce((acc, num) => acc + num, 0);\n return sum / numbers.length;\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Function to debounce another function", | |
| "code": "function debounce(func, delay) {\n let timeoutId;\n return function(...args) {\n clearTimeout(timeoutId);\n timeoutId = setTimeout(() => func.apply(this, args), delay);\n };\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Function to deep clone an object", | |
| "code": "function deepClone(obj) {\n if (obj === null || typeof obj !== 'object') return obj;\n if (obj instanceof Date) return new Date(obj);\n if (obj instanceof Array) return obj.map(item => deepClone(item));\n \n const clonedObj = {};\n for (const key in obj) {\n if (obj.hasOwnProperty(key)) {\n clonedObj[key] = deepClone(obj[key]);\n }\n }\n return clonedObj;\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Promise-based timeout function", | |
| "code": "function timeout(ms) {\n return new Promise(resolve => setTimeout(resolve, ms));\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Function to validate email format", | |
| "code": "function isValidEmail(email) {\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n return emailRegex.test(email);\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Function to capitalize first letter", | |
| "code": "function capitalize(str) {\n if (!str) return '';\n return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Function to remove duplicates from array", | |
| "code": "function removeDuplicates(arr) {\n return [...new Set(arr)];\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Function to chunk array into smaller arrays", | |
| "code": "function chunkArray(arr, size) {\n const chunks = [];\n for (let i = 0; i < arr.length; i += size) {\n chunks.push(arr.slice(i, i + size));\n }\n return chunks;\n}" | |
| }, | |
| { | |
| "language": "javascript", | |
| "task": "boilerplate", | |
| "description": "Function to generate random number in range", | |
| "code": "function randomInRange(min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}" | |
| } | |
| ] |