[just-rotate-right] Rotate array elements to the right
Aberta
- 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
Avaliação
Esta issue ainda não foi avaliada.