Finding User's division

Finds the division to which a user belongs based on their rating.

findUserDivision(user: Object): Promise<string|null>

Finds the division to which a user belongs based on their rating.

  • Parameters:

    • user (Object): An object representing the user with id and rating properties.

  • Returns:

    • Promise<string|null>: A promise that resolves with the name of the division if the user is found and their rating meets the division's criteria, or null if the user is not found in any division or does not meet criteria.

  • Throws:

    • Error: If the user object does not contain rating.

Example Usage:

const RankSystem = require('division-rank');

// Assuming rankSystem is already instantiated with divisions

const user = {
  id: 1,
  rating: 500
};

try {
  const division = rankSystem.findUserDivision(user);
  console.log(division); // Output: 'Silver' (based on the example provided)
} catch (error) {
  console.error(error.message);
}

This method allows you to determine the division of a user based on their rating within the RankSystem instance. Handle promises appropriately in your application to process the division name or handle errors as needed.

Last updated