Skip to content

Commit adb60a5

Browse files
committed
Function #22: Added
1 parent b86b54b commit adb60a5

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

Problem.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
#19: Print in Console the first 100 prime numbers
2020
#20: Check Odd or Even Number with Arguments Objects
2121
#21: Create a function that will return in an array the first "nPrimes" prime numbers greater than a particular number "startAt"
22+
#22: Rotate an array to the left 1 position
2223

2324

2425

2526

2627

2728

28-
#21: Rotate an array to the left 1 position
2929
#22: Rotate an array to the right 1 position
3030
#23: Reverse an array
3131
#24: Reverse a string

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,18 @@ function isPrime(num) {
288288
}
289289
290290
```
291+
292+
**#22: Rotate an array to the left 1 position**
293+
294+
```
295+
296+
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
297+
298+
rotateLeft(arr);
299+
function rotateLeft(arr) {
300+
const arrFirstElement = arr.shift();
301+
arr.push(arrFirstElement);
302+
}
303+
console.log(arr);
304+
305+
```

script.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// #1: Print in Console from 1 to 10 numbers?
1+
/* // #1: Print in Console from 1 to 10 numbers?
22
for (let i = 1; i <= 10; i++) {
33
console.log(i);
44
}
@@ -184,3 +184,13 @@ function isPrime(num) {
184184
}
185185
return num > 1;
186186
}
187+
*/
188+
// #22: Rotate an array to the left 1 position
189+
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
190+
191+
rotateLeft(arr);
192+
function rotateLeft(arr) {
193+
const arrFirstElement = arr.shift();
194+
arr.push(arrFirstElement);
195+
}
196+
console.log(arr);

0 commit comments

Comments
 (0)