[Solved] Need Converting Help C# to F#

Something like this should do the trick: let getEnumDescription value = let fi = value.GetType().GetField(value.ToString()) let attributes = fi.GetCustomAttributes(typedefof<DescriptionAttribute>, false) |> Array.map (fun x -> x :?> DescriptionAttribute) if attributes.Length > 0 then attributes.[0].Description else value.ToString() Then you can call it like so: let red = Color.Red |> getEnumDescription let blue = Color.Blue |> getEnumDescription … Read more

[Solved] Filter an object based on values in an array [duplicate]

You can use reduce to create the result and operator in to check if the key exists: const obj = {“John”:44,”Sarah”:23,”Bob”:43,”Kate”:65,”Bill”:18}; const keys = [‘John’, ‘Bob’, ‘Kate’, ‘Bill’, ‘Fred’]; const result = keys.reduce((acc, el) => { if (el in obj) acc[el] = obj[el]; return acc; }, {}); console.log(result); Another approach is to convert the object … Read more

[Solved] complex list comprehension syntax

You can generally turn a nested for loop that builds a list into a list comprehension by using the same exact for … in statements in the same order: list3 = [k for l in lst1 for k in lst2 if l == k[0]] list4 = [k for l in lst1 for k in lst2 … Read more

[Solved] Swap number bug

As others have pointed out, you can only have one return statement from a function and thus only return on parameter (although it can be a structure). In this instance I would pass the integer values into the function by using integer pointers and passing their address e.g.: int swapNum(int *num1, int *num2); int main() … Read more

[Solved] C# get pair closest to value [closed]

You want something like this: public static Pair FindClosest(IEnumerable<Pair> list, int value) { Pair closest = null; if (list != null && list.Count() > 0) { foreach (var pair in list) { if (value <= pair.Max) { closest = pair; break; } } if (closest == null) { closest = list.Last(); } } return closest; … Read more

[Solved] Push and select data from Array of Objects

besides lack of info provided , this might help you build your own var dataQuestions = [ { question : 1, response : 3, },{ question : 2, response : 7, },{ question : 3, response : 5, }]; function addQ(){ var question = parseInt(document.getElementById(“question”).value); var response = parseInt(document.getElementById(“response”).value); dataQuestions.push( { question: question, response : … Read more

[Solved] How can I solve this String length problem?

Have you tried calculating the length within the function rather than in the console log? This ensures that all of the logic is first completed within the function before it is returned in the console log. Your function expects the string name, but you are passing name.length function getNameLength(name){ return name.length; } console.log(getNameLength(‘John’)); console.log(getNameLength(‘Argentina!’)); console.log(getNameLength(‘Macedonia’)); … Read more

[Solved] how do i send a private message to all people who have a certain role? (discord.js) [closed]

You can use the Role.members property. // get role by name const role = message.guild.roles.cache.find(role => role.name === ‘<roleName>’); // send a message to everyone with the role role.members.each(user => user.send(‘This is a DM’)); This method assumes you have a way to get the <roleName> value from a string; perhaps with an args variable. solved … Read more