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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:43:52+00:00 2026-05-25T09:43:52+00:00

A bit hard to find a proper title… I have an object which basically

  • 0

A bit hard to find a proper title…

I have an object which basically is a wrapper around an array of Cartesian coordinates (x, y values). I’m now defining a few transform methods on that array (move, rotate, skew, mirror). Basically all these methods need an iterator of the array, so I wrote a function iterate:

myList.prototype.iterate = function() {
    var fn = arguments[0];  // first argument is the actual transform function.
    ..

Optionally a second argument may be passed in, which must be an instance of myList. If this argument is passed in, the function operates on a clone of the argument, otherwise it must operate on itself:

    if (arguments.length === 2 and arguments[2].type === this.type) {
        target = $.extend({}, arguments[2]); // deep copy.
    } else {
        target = this;
    }

So far so good, now I’m defining my transformation functions (rotate)

myList.prototype.rotate=function() {
    var rotatePoint = function (angle, pt) {
    return {x : (pt.x * Math.cos(angle) - pt.y* Math.sin(angle))
        , y : (pt.x * Math.sin(angle) + pt.y* Math.cos(angle)) };
    }
    if (arguments.length() === 1)  {    //Alternative for this if statement.
        return this.iterate(rotatePoint.curry(arguments[0]));
    } else {
        return this.iterate(rotatePoint.curry(arguments[0]),arguments[1]);
    }
}

curry is a non standard javascript function, and is described here. I’m not so glad with the if statement. I think it can be done more elegant with apply or call. But I haven’t been able to figure this out. Problem is also that arguments[2] in iterate will be an empty array, screwing my if statement when comparing types.

How can rewrite the if statement in some nice clean javascript code, so that there is no second argument at all when it is not in passed in iterate;

  • 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-25T09:43:53+00:00Added an answer on May 25, 2026 at 9:43 am

    does something like this work?

    var args = $.makeArray(arguments),
        iterator = rotatePoint.curry(args.shift());
    args.unshift(iterator);
    return this.iterate.apply(YOURTHIS, args);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code like this, and I find it a bit hard to read:
It's a little bit hard to find an appropriate title for this. I think
This is something that I always find a bit hard to explain to others:
The situation is a bit hard to explain, I'll do my best. I have
its a little bit hard to understand. in the header.php i have this code:
My problem is a little bit hard but simple. I have (or there is)
we have a particle detector hard-wired to use 16-bit and 8-bit buffers. Every now
I'll admit the title is a bit confusing but it was hard to come
Okay, got a question. I have assembled a bit mask for options. Basically my
This is a bit hard for me to articulate, but in PHP you can

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.