Skip to content

Commit af4da65

Browse files
committed
new cashier does not know about space or shift
1 parent 6ee0fd3 commit af4da65

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

get-order.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// kata - https://www.codewars.com/kata/5d23d89906f92a00267bb83d
2+
// New Cashier Does Not Know About Space or Shift
3+
4+
// Input - String of menu items
5+
// Ouput - String with separated and ordered, order items.
6+
7+
const getOrder = (input) => {
8+
const menu = ['Burger', 'Fries', 'Chicken', 'Pizza', 'Sandwich', 'Onionrings', 'Milkshake', 'Coke'];
9+
const result = [];
10+
for (const item of menu) {
11+
const regexp = new RegExp(item, 'gi');
12+
const foundItems = input.match(regexp);
13+
foundItems && result.push(...foundItems.map((x) => x[0].toUpperCase() + x.slice(1)));
14+
}
15+
return result.join(' ');
16+
};
17+
18+
console.log(
19+
getOrder('milkshakepizzachickenfriescokeburgerpizzasandwichmilkshakepizza'),
20+
'\n',
21+
'Burger Fries Chicken Pizza Pizza Pizza Sandwich Milkshake Milkshake Coke'
22+
);
23+
console.log(getOrder('pizzachickenfriesburgercokemilkshakefriessandwich'), '\n', 'Burger Fries Fries Chicken Pizza Sandwich Milkshake Coke');

0 commit comments

Comments
 (0)