angus-c / angus-c/just

[just-rotate-right] Rotate array elements to the right

Aberta
#537 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
JavaScript
Estrelas
6.2k
Forks
210
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

It would be helpful to introduce a method to rotate array elements. Something this simple would do the trick:

### Function definition
```ts
function rotateRight(arr: T[], k: number): T[] {
const mod = k % arr.length;
return arr.slice(-mod).concat(arr.slice(0, -mod));
}
```

### Usage
```ts
rotateRight([1, 2, 3], 1) // -> [3, 1, 2]
rotateRight([1, 2, 3], -1) // -> [2, 3, 1]
rotateRight([1, 2, 3], 2) // -> [2, 3, 1]
```

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.