let friends = ['Alfonso Waters', 'Mona', 'Mania','Mona Dunn', 'Mae','Mae Lane']
1 Answer
Hope it's not too confusing :)
friends = ['Alfonso Waters', 'Mona', 'Mania','Mona Dunn', 'Mae','Mae Lane']
friends_lenght = friends.map(word => word.length)
friends_lenght_min_index = Math.min(...friends_lenght)
friend_index = friends_lenght.indexOf(friends_lenght_min_index)
friend = friends[friend_index]
// Output
// 'Mae'
p.s. You can make a function out of this code.
2 Comments
Aleksandr Breus
Glad to hear :) Click that this answer is correct so that the system understands that there is a solution. And if you can, please state that the answer was useful.
Ahmed Daud
Thanks, the code writing was very well written so I understood it too easily