const filterByA = arr => {
const res = [];
for(let item of arr) {
if(item != null && item.toString().charAt(0) === 'A') {
res.push(item);
}
}
return res;
}
console.log( filterByA(['Apple', 'Banana', 'Orange', 'Avocado', 'Cheese']) );
const arrayStartsWith = by => arr => {
const res = [];
for(let item of arr) {
if(item != null && item.toString().charAt(0) === by) {
res.push(item);
}
}
return res;
};
const filterByA = arrayStartsWith('A');
const filterByB = arrayStartsWith('B');
let testArr = ['Apple', 'Banana', 'Orange', 'Avocado', 'Cheese', 'Black Chocolate'];
console.log( filterByA(testArr) );
console.log( filterByB(testArr) );