| { | |
| "language": "javascript", | |
| "category": "basics", | |
| "training_data": [ | |
| { | |
| "input": "create a hello world in javascript", | |
| "output": "console.log('Hello, World!');\n", | |
| "tags": ["beginner", "console"] | |
| }, | |
| { | |
| "input": "write a function to add two numbers in javascript", | |
| "output": "function add(a, b) {\n return a + b;\n}\n\nconsole.log(add(5, 3));\n", | |
| "tags": ["functions", "arithmetic"] | |
| }, | |
| { | |
| "input": "create a loop from 1 to 10 in javascript", | |
| "output": "for (let i = 1; i <= 10; i++) {\n console.log(i);\n}\n", | |
| "tags": ["loops", "for"] | |
| }, | |
| { | |
| "input": "write an arrow function", | |
| "output": "const greet = (name) => {\n return `Hello, ${name}!`;\n};\n\nconsole.log(greet('Alice'));\n", | |
| "tags": ["arrow_functions", "es6"] | |
| }, | |
| { | |
| "input": "create an object with properties", | |
| "output": "const person = {\n name: 'John',\n age: 30,\n city: 'New York',\n greet: function() {\n return `Hello, I'm ${this.name}`;\n }\n};\n\nconsole.log(person.greet());\n", | |
| "tags": ["objects", "methods"] | |
| }, | |
| { | |
| "input": "write an array map function", | |
| "output": "const numbers = [1, 2, 3, 4, 5];\nconst squared = numbers.map(x => x * x);\nconsole.log(squared);\n", | |
| "tags": ["array_methods", "map"] | |
| }, | |
| { | |
| "input": "create an async function with fetch", | |
| "output": "async function fetchData(url) {\n try {\n const response = await fetch(url);\n const data = await response.json();\n return data;\n } catch (error) {\n console.error('Error:', error);\n }\n}\n", | |
| "tags": ["async_await", "fetch", "api"] | |
| }, | |
| { | |
| "input": "write a promise with then and catch", | |
| "output": "const promise = new Promise((resolve, reject) => {\n setTimeout(() => resolve('Success!'), 1000);\n});\n\npromise\n .then(result => console.log(result))\n .catch(error => console.error(error));\n", | |
| "tags": ["promises", "async"] | |
| }, | |
| { | |
| "input": "create a class in javascript", | |
| "output": "class Animal {\n constructor(name) {\n this.name = name;\n }\n \n speak() {\n console.log(`${this.name} makes a sound`);\n }\n}\n\nconst dog = new Animal('Dog');\ndog.speak();\n", | |
| "tags": ["classes", "oop"] | |
| }, | |
| { | |
| "input": "write a function to filter array", | |
| "output": "const numbers = [1, 2, 3, 4, 5, 6, 7, 8];\nconst evens = numbers.filter(x => x % 2 === 0);\nconsole.log(evens);\n", | |
| "tags": ["filter", "array_methods"] | |
| }, | |
| { | |
| "input": "create a template string with variables", | |
| "output": "const name = 'Alice';\nconst age = 25;\nconst message = `My name is ${name} and I am ${age} years old`;\nconsole.log(message);\n", | |
| "tags": ["template_strings", "es6"] | |
| }, | |
| { | |
| "input": "write destructuring assignment", | |
| "output": "const person = { name: 'John', age: 30, city: 'NYC' };\nconst { name, age } = person;\nconsole.log(name, age);\n\nconst arr = [1, 2, 3];\nconst [first, second] = arr;\nconsole.log(first, second);\n", | |
| "tags": ["destructuring", "es6"] | |
| }, | |
| { | |
| "input": "create a higher order function", | |
| "output": "function multiplier(factor) {\n return function(number) {\n return number * factor;\n };\n}\n\nconst double = multiplier(2);\nconsole.log(double(5));\n", | |
| "tags": ["higher_order_functions", "closures"] | |
| }, | |
| { | |
| "input": "write a function with spread operator", | |
| "output": "function sum(...numbers) {\n return numbers.reduce((a, b) => a + b, 0);\n}\n\nconsole.log(sum(1, 2, 3, 4, 5));\n", | |
| "tags": ["spread_operator", "rest_parameters"] | |
| }, | |
| { | |
| "input": "create object with methods using this", | |
| "output": "const calculator = {\n value: 0,\n add(num) {\n this.value += num;\n return this;\n },\n multiply(num) {\n this.value *= num;\n return this;\n },\n getResult() {\n return this.value;\n }\n};\n\nconsole.log(calculator.add(5).multiply(2).add(3).getResult());\n", | |
| "tags": ["method_chaining", "this"] | |
| } | |
| ] | |
| } | |