Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8441779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:39:24+00:00 2026-06-10T08:39:24+00:00

I have this range of numbers: 0 ——-> 25 ——-> 80 ——> 150 small

  • 0

I have this range of numbers:

0  -------> 25 ------->  80 ------> 150
    small      medium       large

I want to recieve a number between 0 to 150 and to display whether it is small, medium or big.
30 and 45 are medium because they are between 25 and 80 and 5 is small because it is lower than 25.

I want to create a function that does this matching for this object:

var sizeMap = { small : 25, medium : 80, large : 150 }

(assuming that 0 is the lowest number).

The function should look like:

function returnSize(number) {
    for (item in sizeMap)
       ???????
    return size
}

how do I write this function so it can be flexible for adding new categories (for example: ‘extra large’ : 250). Should I present the object as an array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:39:26+00:00Added an answer on June 10, 2026 at 8:39 am

    To have a deterministic output, I’d prefer to have an array ordered by the categories in question:

    var categories = [ 
      {label: 'small', upTo: 25}, 
      {label: 'medium', upTo: 80}, 
      {label: 'large', upTo: 150} ];
    

    (you can even create this array from your original sizeMap)

    And then you can do:

    function getSizeCategory(number, categories) {
      for (var i = 0; i < categories.length; ++i) {
        if (number < categories[i].upTo) {
          return categories[i].label;
        }
      }
      throw new Error("not in range!");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have VBA select a Range, covering a constant number of columns
So if I have a range of numbers '0 - 1024' and I want
I have a function that verifies if a number falls between two other numbers
I have this following IEnumerable LINQ query: var query = from p in Enumerable.Range(2,
So I have this bit of code for x in range(x1,x2): for y in
I currently have this code : Private Sub Worksheet_Change(ByVal Target As Range) Dim lastrow
I currently have this code Private Sub Worksheet_Change(ByVal Target As Range) WorksheetChanged(Target, Range(AB3).CurrentRegion, Range(B18:B19))
I have create name range on sheet A so I need to use this
I have a list iteration in python defined like this: for i in range(5):
I have locked cells in a spreadsheet using this lines of code. Range(A1:D23).Select Selection.Locked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.