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 8889433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:15:42+00:00 2026-06-14T22:15:42+00:00

Another task for underscore.js – I need to do ‘calibrate’ the data, for displaying

  • 0

Another task for underscore.js – I need to do ‘calibrate’ the data, for displaying it in the chart.

Given: available space: 160 and data: data: [10, 50, 80, 90] I want to get calibratedData: [0, 80, 140, 160].

here’s the algorithm:

  1. get the peaks for the data, Min=10 , Max = 90.
  2. get the difference between Min and Max, 80.
  3. get the Unit space available to 1 unit of change as 160 / 80 = 2
  4. calibrate each item in data, using the ratio from the previous step as:
    d[i] = (d[i]-Min) * Unit, which gives [0, 80, 140, 160].

Wonder if I can accomplish the task using ‘linq’able syntax of underscore.js.

  • 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-14T22:15:44+00:00Added an answer on June 14, 2026 at 10:15 pm

    I don’t understand why people downvoted your question, but it was fun to find the answer. Here it is:

    function calibrate( data, availableSpace ) {
        var min = _.min(data);
        var max = _.max(data);
        var range = max - min;
        var spacePerUnit = availableSpace / range;
        return _.map( data, function (value) {
            return ( value - min ) * spacePerUnit;
        });
    }
    
    alert( calibrate( [10, 50, 80, 90], 160 ) );
    

    You can try it in this JSFiddle.

    The key is to use the map() function in Underscore with this function:

    function (value) {
      return ( value - min ) * spacePerUnit;
    }
    

    This function has access to the min, max and spacePerUnit values in the parent function which makes it very efficient (because it doesn’t do the calculations in every iteration).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Traditional task of iterating trough key set of std::map led me to another mess
i have a task to transfer text files from one pc to another using
I came across the task to find all occurences of a substring in another
Disclaimer: it's just another task for beginner so I'm good with the fact that
A special memory block would be periodically updated by DMA task. When another Task
iv'e got an asp button which performs another task besides postback i have done
I have another task for my school and it is: Write a program which
I have been given the task to fix an Embedded Operating System which is
I have a task which, when completed, is supposed to continue with another task
another in my beginnerish series of questions about VBA. I am in the process

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.