Find the maximum value in an array of enumerated items

Let's consider an enum

enum enumerationTmp {
  a, // 0
  b, // 1
  c  // 2
}

and an array containing elements from this enum

const letters = [enumerationTmp.a, enumerationTmp.b]

How would one determine the maximum value in the array 'letters'?

maxLetters = enumerationTmp.b // since b = 1 and a = 0

Answer №1

When working with enumeration values that are numbers, typical mathematical operations and functions can be used:

let largestNumber = Math.max(...numbers);

For more information, check the following resources:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Reorganizing the index of a numpy array

Looking to convert a 2D array into an image using NumPy. My goal is to transform the 'image' array with dimensions of 140x120 into a 3D array of 140x120x3 by stacking the same array 3 times for a grayscale image to be used with skimage. My attem ...

Find all objects in an array that have a date property greater than today's date and return them

I have an array of objects with a property called createdDate stored as a string. I need to filter out all objects where the createdDate is greater than or equal to today's date. How can this be achieved in typescript/javascript? notMyScrims: Sc ...

What is the process of accessing inner array values in PHP?

I'm struggling with this array structure Array ( [thumbnail] => Array ( [width] => 150 [height] => 150 [crop] => 1 ) [medium] => Array ( [width] => 300 ...

What was the process for implementing the lexer and parser?

My journey into the depths of programming languages led me to explore how TypeScript is implemented, prompting me to venture into its Github repository. Within the language's source code under /src/compiler, I stumbled upon intriguing files like scan ...

A step-by-step guide to extracting serialized data and displaying it in a table using unserialization in

Hello there, I go by the name of Tri. Currently, I am trying to store serialized data into a MySQL database using PHP. However, I am facing an issue with retrieving this data and displaying it in a table after unserialization. After unserializing the da ...

Controlling the Output in Typescript without Restricting the Input

I am interested in passing a function as a parameter, allowing the function to have any number of parameters but restricting the return type to boolean. For example, a function Car(driver: Function) could be defined where driver can be ()=>boolean or ( ...

Angular 5 Image Upload - Transfer your images with ease

I am having trouble saving a simple post in firebase, especially with the image included. This is my current service implementation: uploadAndSave(item: any) { let post = { $key: item.key, title: item.title, description: item.description, url: '&a ...

What is the best way to sort one array and then reorder another array accordingly in Java?

Imagine having an unordered array with possible duplicates int [] nums = {8,1,2,2,3}; Arrays.sort(nums); Next, we have another array int[] count = {0,1,1,3,4}; The goal is to achieve the following transformation Arrays.reorder(count, k->nums.sort()); ...

Subclass method overloading in Typescript

Take a look at this example: class A { method(): void {} } class B extends A { method(a: number, b: string): void {} } An error occurs when trying to implement method() in class B. My goal is to achieve the following functionality: var b: B; b.met ...

Is there a way to perform type narrowing within an Angular template?

I'm facing an issue with a component that requires a business object as an Input. Within the template of this component, I need to conditionally display some content based on the presence of a property that only exists in certain subclasses of the bus ...

Insert an HTML element or Angular component dynamically when a specific function is called in an Angular application

Currently, I am working on a component that contains a button connected to a function in the .ts file. My goal is to have this function add an HTML element or make it visible when the button is clicked. Specifically, I would like a dynamic <div> elem ...

The expected property 'label' is not found in the object type '{ handleClick: () => void; }', but it is required in the object type '{ handleClick: () => void; label: string; }'

I'm encountering difficulties when describing the types of my props. The issue arises with the following code: <PostButton handleClick={props.upvote}/> <PostButton2 handleClick={props.downvote}/> An error message is displayed: Pro ...

Having trouble establishing a connection with mongoose and typescript

When attempting to establish a connection using mongoose, I consistently encounter the errors outlined below. However, if I use MongoClient instead, everything functions as expected. import connectMongo from '../../lib/connectMongo' console.log( ...

Potential keys + keys that are present in the `initialData`

Is there a way to specify the type of data in order to include all keys that exist in initialData plus additional keys from Item as Partial(optional)? class TrackedInstance<Item extends Record<string, any>, InitialData extends Partial<Item> ...

Achieving the desired type of value within a nested record

I am trying to create a unique function that can manipulate values of a nested Record, based on the collection name. However, in my current implementation, I am facing difficulty in attaining the value type: type Player = { name:string } type Point = { x:n ...

Typescript struggling to load the hefty json file

Currently, I am attempting to load a JSON file within my program. Here's the code snippet that I have used: seed.d.ts: declare module "*.json" { const value: any; export default value; } dataset.ts: import * as data from "./my.json" ...

Utilizing Angular 2 or TypeScript to Retrieve Visitor's Location

I initially began using ServerVariables["HTTP_CF_IPCOUNTRY"] on the backend server, but it's proving to be too slow. I'm looking for an Angular or TypeScript alternative to speed things up. ...

What is the best way to access the final element of an array without removing it from the list?

Hey there, I understand how to use array_pop() to remove the last element of an array. But, is there a way to retrieve the last element without removing it? As a little extra challenge: $array = array('x' => 'x', 'y' => ...

Retrieve the non-empty attributes of a JSON object

I have a function in Typescript that extracts specific values from a JSON data object, some of which may be empty. How can I retrieve only certain data fields? Here is the function: let datosCod; for (let get in Object.keys(transfConsData)) { co ...

Zero's JSON Journey

When I make an HTTP request to a JSON server and store the value in a variable, using console.log() displays all the information from the JSON. However, when I try to use interpolation to display this information in the template, it throws the following er ...