← Back to challenges

Fruit Salad πŸ‡πŸ“πŸŽ

JavaScriptHardarraysloopsstringssorting

Instructions

Fruit salads are served best when the fruits are sliced and diced into small chunks!

For this challenge, slice each fruit in half and sort the chunks alphabetically. This recipe tastes best when the chunks are joined together to make a string.

Worked Example

fruitSalad(["apple", "pear", "grapes"]) ➞ "apargrapepesple"

// Chunks: ["ap", "ple", "pe", "ar", "gra", "pes"]
// Sorted chunks: ["ap", "ar", "gra", "pe", "pes", "ple"]
// Final string: "apargrapepesple"

Examples

fruitSalad(["apple", "pear", "grapes"]) ➞ "apargrapepesple"

fruitSalad(["raspberries", "mango"]) ➞ "erriesmangoraspb"

fruitSalad(["banana"]) ➞ "anaban"

Notes

  • If a fruit has an odd number of letters, make the right side larger than the left.
  • For example: "apple" will be sliced into "ap" and "ple".
  • All fruits will be given in lowercase.
javascript
Loading editor…
⌘ ↡ to run
Walks through the solution with reasoning and edge cases.
Next: Automorphic Numbers β†’