sabia-js-inline-functions-one / javascript_training_data_expanded.json
gregoriorojas's picture
filter and map js function - added first training set for
0ea011a verified
[
{
"instruction": "Use map function to double each element in an array.",
"input": "[1, 2, 3, 4]",
"output": "function double(x) {\n return x * 2;\n}\n\nlet result = array.map(double);"
},
{
"instruction": "Use filter function to get only even numbers from an array.",
"input": "[1, 2, 3, 4, 5, 6]",
"output": "function isEven(x) {\n return x % 2 === 0;\n}\n\nlet result = array.filter(isEven);"
},
{
"instruction": "Use map function to square each element in an array.",
"input": "[1, 2, 3, 4]",
"output": "function square(x) {\n return x * x;\n}\n\nlet result = array.map(square);"
},
{
"instruction": "Use filter function to get only numbers greater than 3 from an array.",
"input": "[1, 2, 3, 4, 5]",
"output": "function greaterThanThree(x) {\n return x > 3;\n}\n\nlet result = array.filter(greaterThanThree);"
},
{
"instruction": "Use map function to convert each element in an array to a string.",
"input": "[1, 2, 3, 4]",
"output": "function toString(x) {\n return x.toString();\n}\n\nlet result = array.map(toString);"
},
{
"instruction": "Use filter function to get only numbers less than 5 from an array.",
"input": "[3, 5, 8, 1, 4]",
"output": "function lessThanFive(x) {\n return x < 5;\n}\n\nlet result = array.filter(lessThanFive);"
},
{
"instruction": "Use map function to add 10 to each element in an array.",
"input": "[5, 10, 15]",
"output": "function addTen(x) {\n return x + 10;\n}\n\nlet result = array.map(addTen);"
},
{
"instruction": "Use filter function to get only odd numbers from an array.",
"input": "[2, 3, 4, 5, 6]",
"output": "function isOdd(x) {\n return x % 2 !== 0;\n}\n\nlet result = array.filter(isOdd);"
},
{
"instruction": "Use map function to negate each element in an array.",
"input": "[-1, 2, -3, 4]",
"output": "function negate(x) {\n return -x;\n}\n\nlet result = array.map(negate);"
},
{
"instruction": "Use filter function to get only positive numbers from an array.",
"input": "[-3, -2, 0, 2, 4]",
"output": "function isPositive(x) {\n return x > 0;\n}\n\nlet result = array.filter(isPositive);"
},
{
"instruction": "Use map function to get the length of each string in an array.",
"input": "[\"apple\", \"banana\", \"cherry\"]",
"output": "function getLength(x) {\n return x.length;\n}\n\nlet result = array.map(getLength);"
},
{
"instruction": "Use filter function to get only strings longer than 4 characters from an array.",
"input": "[\"apple\", \"cat\", \"banana\"]",
"output": "function longerThanFour(x) {\n return x.length > 4;\n}\n\nlet result = array.filter(longerThanFour);"
},
{
"instruction": "Use map function to convert each string in an array to uppercase.",
"input": "[\"apple\", \"banana\", \"cherry\"]",
"output": "function toUpperCase(x) {\n return x.toUpperCase();\n}\n\nlet result = array.map(toUpperCase);"
},
{
"instruction": "Use filter function to get only strings containing the letter 'a' from an array.",
"input": "[\"apple\", \"dog\", \"banana\", \"cherry\"]",
"output": "function containsA(x) {\n return x.includes('a');\n}\n\nlet result = array.filter(containsA);"
},
{
"instruction": "Use map function to multiply each element in an array by 3.",
"input": "[1, 2, 3, 4]",
"output": "function multiplyByThree(x) {\n return x * 3;\n}\n\nlet result = array.map(multiplyByThree);"
},
{
"instruction": "Use filter function to get only numbers divisible by 2 from an array.",
"input": "[1, 2, 3, 4, 5, 6]",
"output": "function isDivisibleByTwo(x) {\n return x % 2 === 0;\n}\n\nlet result = array.filter(isDivisibleByTwo);"
},
{
"instruction": "Use map function to subtract 1 from each element in an array.",
"input": "[1, 2, 3, 4]",
"output": "function subtractOne(x) {\n return x - 1;\n}\n\nlet result = array.map(subtractOne);"
},
{
"instruction": "Use filter function to get only non-negative numbers from an array.",
"input": "[-1, 0, 1, 2, -2]",
"output": "function isNonNegative(x) {\n return x >= 0;\n}\n\nlet result = array.filter(isNonNegative);"
},
{
"instruction": "Use map function to append '!' to each string in an array.",
"input": "[\"hello\", \"world\"]",
"output": "function appendExclamation(x) {\n return x + '!';\n}\n\nlet result = array.map(appendExclamation);"
},
{
"instruction": "Use filter function to get only strings that start with the letter 'b' from an array.",
"input": "[\"apple\", \"banana\", \"cherry\", \"blueberry\"]",
"output": "function startsWithB(x) {\n return x.startsWith('b');\n}\n\nlet result = array.filter(startsWithB);"
},
{
"instruction": "Use map function to get the names of all persons in an array of person objects.",
"input": "[{\"name\": \"Alice\", \"age\": 30}, {\"name\": \"Bob\", \"age\": 25}]",
"output": "function getName(person) {\n return person.name;\n}\n\nlet result = array.map(getName);"
},
{
"instruction": "Use filter function to get all persons older than 25 in an array of person objects.",
"input": "[{\"name\": \"Alice\", \"age\": 30}, {\"name\": \"Bob\", \"age\": 25}]",
"output": "function isOlderThan25(person) {\n return person.age > 25;\n}\n\nlet result = array.filter(isOlderThan25);"
},
{
"instruction": "Use map function to get the names of all cars in an array of car objects.",
"input": "[{\"make\": \"Toyota\", \"model\": \"Corolla\"}, {\"make\": \"Honda\", \"model\": \"Civic\"}]",
"output": "function getCarName(car) {\n return car.make + ' ' + car.model;\n}\n\nlet result = array.map(getCarName);"
},
{
"instruction": "Use filter function to get all cars of a specific make in an array of car objects.",
"input": "[{\"make\": \"Toyota\", \"model\": \"Corolla\"}, {\"make\": \"Honda\", \"model\": \"Civic\"}]",
"output": "function isToyota(car) {\n return car.make === 'Toyota';\n}\n\nlet result = array.filter(isToyota);"
},
{
"instruction": "Use map function to get the names of all cities in an array of city objects.",
"input": "[{\"name\": \"New York\", \"population\": 8000000}, {\"name\": \"Los Angeles\", \"population\": 4000000}]",
"output": "function getCityName(city) {\n return city.name;\n}\n\nlet result = array.map(getCityName);"
},
{
"instruction": "Use filter function to get all cities with a population greater than 5 million in an array of city objects.",
"input": "[{\"name\": \"New York\", \"population\": 8000000}, {\"name\": \"Los Angeles\", \"population\": 4000000}]",
"output": "function isLargeCity(city) {\n return city.population > 5000000;\n}\n\nlet result = array.filter(isLargeCity);"
},
{
"instruction": "Use map function to get the ages of all persons in an array of person objects.",
"input": "[{\"name\": \"Alice\", \"age\": 30}, {\"name\": \"Bob\", \"age\": 25}]",
"output": "function getAge(person) {\n return person.age;\n}\n\nlet result = array.map(getAge);"
},
{
"instruction": "Use filter function to get all persons younger than 30 in an array of person objects.",
"input": "[{\"name\": \"Alice\", \"age\": 30}, {\"name\": \"Bob\", \"age\": 25}]",
"output": "function isYoungerThan30(person) {\n return person.age < 30;\n}\n\nlet result = array.filter(isYoungerThan30);"
},
{
"instruction": "Use map function to get the full names of all persons in an array of person objects with first and last names.",
"input": "[{\"firstName\": \"Alice\", \"lastName\": \"Smith\"}, {\"firstName\": \"Bob\", \"lastName\": \"Johnson\"}]",
"output": "function getFullName(person) {\n return person.firstName + ' ' + person.lastName;\n}\n\nlet result = array.map(getFullName);"
},
{
"instruction": "Use filter function to get all cars of a specific model in an array of car objects.",
"input": "[{\"make\": \"Toyota\", \"model\": \"Corolla\"}, {\"make\": \"Honda\", \"model\": \"Civic\"}]",
"output": "function isCorolla(car) {\n return car.model === 'Corolla';\n}\n\nlet result = array.filter(isCorolla);"
},
{
"instruction": "Use map function to get the populations of all cities in an array of city objects.",
"input": "[{\"name\": \"New York\", \"population\": 8000000}, {\"name\": \"Los Angeles\", \"population\": 4000000}]",
"output": "function getPopulation(city) {\n return city.population;\n}\n\nlet result = array.map(getPopulation);"
},
{
"instruction": "Use filter function to get all cities with a name starting with 'N' in an array of city objects.",
"input": "[{\"name\": \"New York\", \"population\": 8000000}, {\"name\": \"Los Angeles\", \"population\": 4000000}]",
"output": "function nameStartsWithN(city) {\n return city.name.startsWith('N');\n}\n\nlet result = array.filter(nameStartsWithN);"
},
{
"instruction": "Use map function to get the initials of all persons in an array of person objects with first and last names.",
"input": "[{\"firstName\": \"Alice\", \"lastName\": \"Smith\"}, {\"firstName\": \"Bob\", \"lastName\": \"Johnson\"}]",
"output": "function getInitials(person) {\n return person.firstName.charAt(0) + person.lastName.charAt(0);\n}\n\nlet result = array.map(getInitials);"
},
{
"instruction": "Use filter function to get all persons with last names starting with 'S' in an array of person objects.",
"input": "[{\"firstName\": \"Alice\", \"lastName\": \"Smith\"}, {\"firstName\": \"Bob\", \"lastName\": \"Johnson\"}]",
"output": "function lastNameStartsWithS(person) {\n return person.lastName.startsWith('S');\n}\n\nlet result = array.filter(lastNameStartsWithS);"
},
{
"instruction": "Use map function to get the lengths of car models in an array of car objects.",
"input": "[{\"make\": \"Toyota\", \"model\": \"Corolla\"}, {\"make\": \"Honda\", \"model\": \"Civic\"}]",
"output": "function getModelLength(car) {\n return car.model.length;\n}\n\nlet result = array.map(getModelLength);"
},
{
"instruction": "Use filter function to get all cars with a model length greater than 5 in an array of car objects.",
"input": "[{\"make\": \"Toyota\", \"model\": \"Corolla\"}, {\"make\": \"Honda\", \"model\": \"Civic\"}]",
"output": "function modelLengthGreaterThan5(car) {\n return car.model.length > 5;\n}\n\nlet result = array.filter(modelLengthGreaterThan5);"
},
{
"instruction": "Use map function to get the uppercased names of all cities in an array of city objects.",
"input": "[{\"name\": \"New York\", \"population\": 8000000}, {\"name\": \"Los Angeles\", \"population\": 4000000}]",
"output": "function getUppercasedName(city) {\n return city.name.toUpperCase();\n}\n\nlet result = array.map(getUppercasedName);"
},
{
"instruction": "Use filter function to get all cities with a name containing 'o' in an array of city objects.",
"input": "[{\"name\": \"New York\", \"population\": 8000000}, {\"name\": \"Los Angeles\", \"population\": 4000000}]",
"output": "function nameContainsO(city) {\n return city.name.includes('o');\n}\n\nlet result = array.filter(nameContainsO);"
},
{
"instruction": "Use map function to get the lowercase names of all cars in an array of car objects.",
"input": "[{\"make\": \"Toyota\", \"model\": \"Corolla\"}, {\"make\": \"Honda\", \"model\": \"Civic\"}]",
"output": "function getLowercasedName(car) {\n return car.make.toLowerCase() + ' ' + car.model.toLowerCase();\n}\n\nlet result = array.map(getLowercasedName);"
},
{
"instruction": "Use filter function to get all cars with a make containing 'o' in an array of car objects.",
"input": "[{\"make\": \"Toyota\", \"model\": \"Corolla\"}, {\"make\": \"Honda\", \"model\": \"Civic\"}]",
"output": "function makeContainsO(car) {\n return car.make.includes('o');\n}\n\nlet result = array.filter(makeContainsO);"
}
]