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

  • Home
  • SEARCH
  • 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 6092113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:24:18+00:00 2026-05-23T12:24:18+00:00

>>> def clockwise(r): … return list(r[0]) + clockwise(list(reversed(zip(*r[1:])))) if r else [] … >>>

  • 0
>>> def clockwise(r):
...     return list(r[0]) + clockwise(list(reversed(zip(*r[1:])))) if r else []
... 
>>> a = [ 
...   [ 1,  2,  3], 
...   [ 5,  6,  7], 
...   [ 9, 10, 11]]
>>> clockwise(a)
[1, 2, 3, 7, 11, 10, 9, 5, 6]

I’m trying to change the function clockwise into Javascript but can’t seem to get it to work.

I’ve created some methods with similar functions:

function zip(masterArray){//zips 2 arrays
var innerLoop = masterArray.length; //inner loop
var outerLoop = 0;
//get length of shortest
for (var i = 0; i<masterArray.length;i++){
    var a = masterArray[i].length;
    if (outerLoop==0){outerLoop = a;}else if(a < outerLoop){outerLoop = a;}
}

var newOuterArray = new Array(outerLoop);
    for (var x = 0; x<outerLoop;x++){
        var newInnerArray = new Array(innerLoop);
            for (var y = 0; y<innerLoop;y++){
                newInnerArray[y] = masterArray[y][x];
                }
            newOuterArray[x] = newInnerArray;
}
 return newOuterArray;
}

function reversed(arr){
    var newArray = new Array(arr.length);
    var n = 0;
    for(var i=arr.length-1; i>=0; i--){
        newArray[n++] = arr[i];
    }
    return newArray;
}

function clockwise(r){

    if(r.length>0){
            var a = reversed(zip(r.slice(1)));
            a.splice(0,0,r[0]);
            return clockwise(a);
     }else{
        return [];
    }
}

Here’s my progress. I’m stuck at the last part: clockwise error in firebug is too much recursion.

  • 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-23T12:24:19+00:00Added an answer on May 23, 2026 at 12:24 pm

    I think the problem lies in the use of splice. Try something like this instead…

    function clockwise(r){
        if(r.length>0){
            var remaining = r.slice(1)
            var a = reversed(zip(remaining));
            return r[0].concat(clockwise(a));
         } else {
            return [];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
def makecounter(): return collections.defaultdict(int) class RankedIndex(object): def __init__(self): self._inverted_index = collections.defaultdict(list) self._documents = []
def isBig(x): if x > 4: return 'apple' else: return 'orange' This works: if
def subStringMatchExact(target, key): if (target.find(key) == -1): return [] else: foundStringAt = [target.find(key)] target
def common_elements(list1, list2): Return a list containing the elements which are in both list1
def self.get(server) return unless server server = server.to_s if klass = @handlers[server] obj =
def any? if block_given? method_missing(:any?) { |*block_args| yield(*block_args) } else !empty? end end In
def record return unless @supported klasses = profile_options[:formats].map { |f| RubyProf.const_get(#{f.to_s.camelize}Printer) }.compact klasses.each do
def merge(l1,l2): i=0; while((l1[i]!=none)||(l2[i]!=none)): SyntaxError: invalid syntax being a newbie i can't figure out
def _table_(request,id,has_permissions): dict = {} dict.update(get_newdata(request,rid)) return render_to_response('home/_display.html',context_instance=RequestContext(request,{'dict': dict, 'rid' : rid, 'has_permissions' :

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.