-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeastsOfManyBeasts.js
More file actions
15 lines (10 loc) · 923 Bytes
/
FeastsOfManyBeasts.js
File metadata and controls
15 lines (10 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ll of the animals are having a feast! Each animal is bringing one dish. There is just one rule: the dish must start and end with the same letters as the animal's name. For example, the great blue heron is bringing garlic naan and the chickadee is bringing chocolate cake.
Write a function feast that takes the animal's name and dish as arguments and returns true or false to indicate whether the beast is allowed to bring the dish to the feast.
Assume that beast and dish are always lowercase strings, and that each has at least two letters. beast and dish may contain hyphens and spaces, but these will not appear at the beginning or end of the string. They will not contain numerals.
function feast(beast, dish) {
return dish.startsWith(beast[0]) && dish.endsWith(beast[beast.length-1])
}
or
function feast(beast, dish) {
return beast[0] === dish[0] && beast[beast.length - 1] === dish[dish.length - 1]
}