instruction
stringlengths 52
110
| output
stringlengths 43
176
| input
stringlengths 11
93
|
---|---|---|
Use map function to double each element in an array. | const result = [1, 2, 3, 4].map(x => x * 2); | [1, 2, 3, 4] |
Use filter function to get only even numbers from an array. | const result = [1, 2, 3, 4, 5, 6].filter(x => x % 2 === 0); | [1, 2, 3, 4, 5, 6] |
Use map function to square each element in an array. | const result = [1, 2, 3, 4].map(x => x * x); | [1, 2, 3, 4] |
Use filter function to get only numbers greater than 3 from an array. | const result = [1, 2, 3, 4, 5].filter(x => x > 3); | [1, 2, 3, 4, 5] |
Use map function to convert each element in an array to a string. | const result = [1, 2, 3, 4].map(x => x.toString()); | [1, 2, 3, 4] |
Use filter function to get only numbers less than 5 from an array. | const result = [3, 5, 8, 1, 4].filter(x => x < 5); | [3, 5, 8, 1, 4] |
Use map function to add 10 to each element in an array. | const result = [5, 10, 15].map(x => x + 10); | [5, 10, 15] |
Use filter function to get only odd numbers from an array. | const result = [2, 3, 4, 5, 6].filter(x => x % 2 !== 0); | [2, 3, 4, 5, 6] |
Use map function to negate each element in an array. | const result = [-1, 2, -3, 4].map(x => -x); | [-1, 2, -3, 4] |
Use filter function to get only positive numbers from an array. | const result = [-3, -2, 0, 2, 4].filter(x => x > 0); | [-3, -2, 0, 2, 4] |
Use map function to get the length of each string in an array. | const result = ["apple", "banana", "cherry"].map(x => x.length); | ["apple", "banana", "cherry"] |
Use filter function to get only strings longer than 4 characters from an array. | const result = ["apple", "cat", "banana"].filter(x => x.length > 4); | ["apple", "cat", "banana"] |
Use map function to convert each string in an array to uppercase. | const result = ["apple", "banana", "cherry"].map(x => x.toUpperCase()); | ["apple", "banana", "cherry"] |
Use filter function to get only strings containing the letter 'a' from an array. | const result = ["apple", "dog", "banana", "cherry"].filter(x => x.includes('a')); | ["apple", "dog", "banana", "cherry"] |
Use map function to multiply each element in an array by 3. | const result = [1, 2, 3, 4].map(x => x * 3); | [1, 2, 3, 4] |
Use filter function to get only numbers divisible by 2 from an array. | const result = [1, 2, 3, 4, 5, 6].filter(x => x % 2 === 0); | [1, 2, 3, 4, 5, 6] |
Use map function to subtract 1 from each element in an array. | const result = [1, 2, 3, 4].map(x => x - 1); | [1, 2, 3, 4] |
Use filter function to get only non-negative numbers from an array. | const result = [-1, 0, 1, 2, -2].filter(x => x >= 0); | [-1, 0, 1, 2, -2] |
Use map function to append '!' to each string in an array. | const result = ["hello", "world"].map(x => x + '!'); | ["hello", "world"] |
Use filter function to get only strings that start with the letter 'b' from an array. | const result = ["apple", "banana", "cherry", "blueberry"].filter(x => x.startsWith('b')); | ["apple", "banana", "cherry", "blueberry"] |
Use map function to get the names of all persons in an array of person objects. | const result = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}].map(person => person.name); | [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}] |
Use filter function to get all persons older than 25 in an array of person objects. | const result = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}].filter(person => person.age > 25); | [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}] |
Use map function to get the names of all cars in an array of car objects. | const result = [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}].map(car => car.make + ' ' + car.model); | [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}] |
Use filter function to get all cars of a specific make in an array of car objects. | const result = [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}].filter(car => car.make === 'Toyota'); | [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}] |
Use map function to get the names of all cities in an array of city objects. | const result = [{"name": "New York", "population": 8000000}, {"name": "Los Angeles", "population": 4000000}].map(city => city.name); | [{"name": "New York", "population": 8000000}, {"name": "Los Angeles", "population": 4000000}] |
Use filter function to get all cities with a population greater than 5 million in an array of city objects. | const result = [{"name": "New York", "population": 8000000}, {"name": "Los Angeles", "population": 4000000}].filter(city => city.population > 5000000); | [{"name": "New York", "population": 8000000}, {"name": "Los Angeles", "population": 4000000}] |
Use map function to get the ages of all persons in an array of person objects. | const result = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}].map(person => person.age); | [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}] |
Use filter function to get all persons younger than 30 in an array of person objects. | const result = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}].filter(person => person.age < 30); | [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}] |
Use map function to get the full names of all persons in an array of person objects with first and last names. | const result = [{"firstName": "Alice", "lastName": "Smith"}, {"firstName": "Bob", "lastName": "Johnson"}].map(person => person.firstName + ' ' + person.lastName); | [{"firstName": "Alice", "lastName": "Smith"}, {"firstName": "Bob", "lastName": "Johnson"}] |
Use filter function to get all cars of a specific model in an array of car objects. | const result = [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}].filter(car => car.model === 'Corolla'); | [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}] |
Use map function to get the populations of all cities in an array of city objects. | const result = [{"name": "New York", "population": 8000000}, {"name": "Los Angeles", "population": 4000000}].map(city => city.population); | [{"name": "New York", "population": 8000000}, {"name": "Los Angeles", "population": 4000000}] |
Use filter function to get all cities with a name starting with 'N' in an array of city objects. | const result = [{"name": "New York", "population": 8000000}, {"name": "Los Angeles", "population": 4000000}].filter(city => city.name.startsWith('N')); | [{"name": "New York", "population": 8000000}, {"name": "Los Angeles", "population": 4000000}] |
Use map function to get the initials of all persons in an array of person objects with first and last names. | const result = [{"firstName": "Alice", "lastName": "Smith"}, {"firstName": "Bob", "lastName": "Johnson"}].map(person => person.firstName.charAt(0) + person.lastName.charAt(0)); | [{"firstName": "Alice", "lastName": "Smith"}, {"firstName": "Bob", "lastName": "Johnson"}] |
Use filter function to get all persons with last names starting with 'S' in an array of person objects. | const result = [{"firstName": "Alice", "lastName": "Smith"}, {"firstName": "Bob", "lastName": "Johnson"}].filter(person => person.lastName.startsWith('S')); | [{"firstName": "Alice", "lastName": "Smith"}, {"firstName": "Bob", "lastName": "Johnson"}] |
Use map function to get the lengths of car models in an array of car objects. | const result = [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}].map(car => car.model.length); | [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}] |
Use filter function to get all cars with a model length greater than 5 in an array of car objects. | const result = [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}].filter(car => car.model.length > 5); | [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}] |
Use map function to get the uppercased names of all cities in an array of city objects. | const result = [{"name": "New York", "population": 8000000}, {"name": "Los Angeles", "population": 4000000}].map(city => city.name.toUpperCase()); | [{"name": "New York", "population": 8000000}, {"name": "Los Angeles", "population": 4000000}] |
Use filter function to get all cities with a name containing 'o' in an array of city objects. | const result = [{"name": "New York", "population": 8000000}, {"name": "Los Angeles", "population": 4000000}].filter(city => city.name.includes('o')); | [{"name": "New York", "population": 8000000}, {"name": "Los Angeles", "population": 4000000}] |
Use map function to get the lowercase names of all cars in an array of car objects. | const result = [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}].map(car => car.make.toLowerCase() + ' ' + car.model.toLowerCase()); | [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}] |
Use filter function to get all cars with a make containing 'o' in an array of car objects. | const result = [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}].filter(car => car.make.includes('o')); | [{"make": "Toyota", "model": "Corolla"}, {"make": "Honda", "model": "Civic"}] |