Kata Description: The Western Suburbs Croquet Club has two categories of membership, Senior and Open. They would like your help with an application form that will tell prospective members which category they will be placed. To be a senior, a member must be at least 55 years old and have a handicap greater than 7. In this croquet club, handicaps range from -2 to +26; the better the player the lower the handicap. Input Input will consist of a list of lists containing two items each. Each list contains information for a single potential member. Information consists of an integer for the person's age and an integer for the person's handicap. Example Input
[[18, 20],[45, 2],[61, 12],[37, 6],[21, 21],[78, 9]]
Output Output will consist of a list of string values (in Haskell: Open or Senior) stating whether the respective member is to be placed in the senior or open category. Example Output
["Open", "Open", "Senior", "Open", "Open", "Senior"]
I have solved this Answer in three different languages: Python, C#, and finally JavaScript, my code is below. C#:
using System;
using System.Collections.Generic;
using System.Linq;
public class Kata
{
public static IEnumerable<string> OpenOrSenior(int[][] data) => data.Select(x => { return (x[0] >= 55 && x[1] > 7) ? "Senior" : "Open"; });
}
Python:
def openOrSenior(array): return [ "Senior" if (x[0] >= 55 and x[1] > 7) else "Open" for x in array]
JavaScript:
function openOrSenior(data) { return data.map(x => { if(x[0] >= 55 && x[1] > 7){return "Senior";}else{return "Open";} }); }
I'm having trouble though solving this problem in F#... I'm new to F#, I have Fuchu tests' already written out. I need some help on some changes I should make to my F# code if possible. F#: The function parameter needs to take a 2D array.
let OpenOrSenior _ =
let mutable _list : List<string> = []
let mutable _val : string = ""
for i in _ do
_val <- if i.[0] >= 55 && i.[1] > 7 then "Senior" else "Open"
_list <- _val :: _list
Please let me know what you think. Thanks in advance.
let OpenOrSenior x = x |> Seq.map (fun _x -> if _x.[0] >= 75 && _x.[1] then "Senior" else "Open" )- Gringo Jaimes