function friend(friends) {
let names = [];
for (let name of friends) {
if (name.length < 5) {
names.push(name);
}
}
return names;
}
let names = friend(["Lena", "Vitya", "Kim", "Kira", "Yasha"]);
console.log(names);
function friend(friends) {
newArr = [];
for (let s of friends) {
if (s.length <= 3) {
newArr.push(s);
}
}
console.log(newArr);
}
А ещё проще: function friend(friends) {
newArr = friends.filter(s => s.length <= 3);
console.log(newArr);
}
P.S. Ты почему-то упорно не используешь let / const / var. /^[a-z]{1,3}$/i.test(s)
Это если не более 3 символов.
А если имя любой длины, то: /^[a-z]+$/i.test(s)
function friend(friends) {
let result = [];
friends.map(short => {
if (short.length < 5) {
result.push(short)
}
});
console.log(result);
}
friend(["Lena", "Vitya", "Kim", "Kira", "Yasha", "Vieeetya"]);