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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:58:09+00:00 2026-05-18T23:58:09+00:00

I bet the following situation can be more efficient by removing the part from

  • 0

I bet the following situation can be more efficient by removing the part from jc.half = jc.half();. I’m just not quite sure how.

jc.half = function(){

    if(jc.singlerow){
        return jc.total
    }else{
        return jc.total / 2;
    }

}
// returns function()

jc.half = jc.half();
// returns the right integer

I’m looking for a solution that does something like this:

jc.half = returnInteger(function(){

    if(jc.singlerow){
        return jc.total
    }else{
        return jc.total / 2;
    }

})
// returns the right integer
  • 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-05-18T23:58:09+00:00Added an answer on May 18, 2026 at 11:58 pm
    jc.half = (function() {
      return jc.singlerow ? jc.total : jc.total / 2;
    })();
    

    The trick is that when you’ve got a function declaration that starts in such a way that the parser can tell that it’s meant to be a value in an expression, then the function definition is part of the expression, and you can use it that way and invoke the function. Really, on the right side of an assignment like that, it’s not even necessary to use the “wrapper” parentheses, but I do it just out of habit and to keep things clear to myself when reading code.

    Of course in this case you could omit the function entirely.

    jc.half = jc.singlerow ? jc.total : jc.total / 2;
    

    edit — a helpful commenter notes that you mention you need an integer; if so, you’ll want to call Math.floor() or Math.round() on your result. Or you could “cheat” a little and do this:

    jc.half = ~~(jc.singlerow ? jc.total : jc.total / 2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following javascript: <script type=text/javascript> function changeBet(parseFloat(bet)) { var moneyline = parseFloat(<?php
I have the following structure passed from jquery to php. I can't seem to
I'm still a graphics programming novice and bet the following problem is just a
My game was just rejected from the AppStore for the following two reasons... We
I bet this is easy but been trying for a while and can't seem
Is flash the best bet to keep images from being stolen? Is there any
I'm looking for a way get the following from a users youtube name or
the following is part of a socket class that im working on. what i
Since $(table).delegate(td, hover, function(){ $(this).toggleClass(hover); }); Is equivalent to the following code written using
With the ruby ternary operator we can write the following logic for a simple

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.