-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathI guess this is a 7kyu kata #6: Fruit Ninja I.js
29 lines (21 loc) · 1.22 KB
/
I guess this is a 7kyu kata #6: Fruit Ninja I.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
I guess this is a ?kyu kata. series #6:
Fruit Ninja I
Description
You are a Fruit Ninja, your skill is cutting fruit. All the fruit will be cut in half by your knife. For example:
[ "apple", "pear", "banana" ] -->
["app", "le", "pe", "ar", "ban", "ana"]
As you see, all fruits are cut in half. You should pay attention to "apple": if you cannot cut a fruit into equal parts, then the first part will has a extra character.
You should only cut the fruit, other things should not be cut, such as the "bomb":
[ "apple", "pear", "banana", "bomb"] -->
["app", "le", "pe", "ar", "ban", "ana", "bomb"]
The valid fruit names are preloded for you as:
fruitsName
Task
Complete function cutFruits that accepts argument fruits. Returns the result in accordance with the rules above.
OK, that's all. I guess this is a 7kyu kata. If you agree, please rank it as 7kyu and vote very;-) If you think this kata is too easy or too hard, please shame me by rank it as you want and vote somewhat or none :[
Click here for more more "I guess this is ...kyu" katas!
*/
function cutFruits(fruits){
return fruits.map(v=>fruitsName.includes(v)?v.slice(0,Math.round(v.length/2))+','+v.slice(Math.round(v.length/2)):v).join(',').split(',')
}