function filterByA(arr) {
var res = [];
for(var i = 0, item; i !== arr.length; i++) {
item = arr[i];
if(item != null && item.toString().charAt(0).toLowerCase() === 'a') {
res.push(item);
}
}
return res;
}
console.log( filterByA(['apple', 'banana', 'orange', 'avocado', 'cheese']) );
const filterByA = arr => {
const res = [];
for(let item of arr) {
if(item != null && item.toString().startsWith('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().startsWith(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) );