Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

rotate array

public static int[] Rotate(int[] arr , int k)
{
    k %= arr.Length;

    var ls = new int[arr.Length];

    for (int i = 0; i < ls.Length-k; i++)
    {
        ls[i+k] = arr[i];
    }
    var j = ls.Length-k;
    for (int i = 0; i < k; i++)
    {
        ls[i] = arr[j++];
    }

    return ls;
}
Comment

how to rotate an array in javascript

function arrayRotate(arr, reverse) {
  if (reverse) arr.unshift(arr.pop());
  else arr.push(arr.shift());
  return arr;
}
Comment

How to rotate a matrix in an array in javascript

function rotate(matrix) {
  return matrix[0].map((col, i) => matrix.map((row) => row[i]))
}

function rotateAntiClockwise(matrix) {
  return matrix[0].map((col, i) => matrix.map((row) => row[i]).reverse())
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: String.toLower() js 
Javascript :: express req get json 
Javascript :: focus element javascript 
Javascript :: javascript list has item 
Javascript :: javascript object without undefined values 
Javascript :: validationResult is not defined 
Javascript :: how to return a factorial in javascript 
Javascript :: simple alert program in javascript 
Javascript :: js sort number array 
Javascript :: js stairs algorithm 
Javascript :: user input in js 
Javascript :: jquery get 2 hours frmo now 
Javascript :: node js event emitter 
Javascript :: Iteration over JS object 
Javascript :: what is status 400 in react 
Javascript :: react webpack config example 
Javascript :: puppeteer headless 
Javascript :: Send Post Fetch REquest With Django 
Javascript :: leap year function javascript 
Javascript :: types of loops in javascript 
Javascript :: text.toUpperCase is not a function 
Javascript :: react native filter list 
Javascript :: json_insert mysql 
Javascript :: hide column in antd table using js / react with conditional rendering 
Javascript :: node js check if called from module 
Javascript :: Converting file to base64 on Javascript client side 
Javascript :: change property in array of objects javascript 
Javascript :: how to stop re rendering in react 
Javascript :: js new array from new set 
Javascript :: js encode url 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =