How to Solve HackerRank’s Left Rotation Problem (JavaScript)

  1. Draw it out; and do it manually as a human would
  2. Take those steps, and write it out, or pseudo code it into steps
  3. THEN begin translating that into code.
  1. Take the first element of the array…
  2. Put in the back
  3. Repeat this as many times as d says.
function rotLeft(a, d) {   while (d) {      a.push(a.shift());      d--;   }return a;}
while (d)
d--
a.push(a.shift());

--

--

--

Always learning.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Add Firebase Analytics to a Gatsby Project

Beginning with React Native

The Beauty of Learning Something New(How I learned Node.js)

Learning React: Components and Props Basics

Interview Questions — BlogPost_408

Scott Barnes Mobile Application

jest斷言

Node.JS: Engine EJS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Saul Feliz

Saul Feliz

Always learning.

More from Medium

AlphaCamp Leetcode 訓練營 05. Linked-List — 觀念入門

LeetCode #994: Rotting Oranges Problem

Most frequently asked questions to crack full stack developer interviews

Byte size info: Stack data Structures