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