Adding some small code challenges + some interesting functions
This commit is contained in:
16
_small_exercices/reverse_array.js
Normal file
16
_small_exercices/reverse_array.js
Normal file
@@ -0,0 +1,16 @@
|
||||
// Write your code here:
|
||||
|
||||
// the method .reverse() does it but is NOT allowed here
|
||||
|
||||
function reverseArray(array) {
|
||||
let newArray = [];
|
||||
for (const element of array) {
|
||||
newArray.unshift(element); // this will put every read element FIRST in the array
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
|
||||
const sentence = ['sense.','make', 'all', 'will', 'This'];
|
||||
|
||||
console.log(reverseArray(sentence))
|
||||
// Should print ['This', 'will', 'all', 'make', 'sense.'];
|
||||
Reference in New Issue
Block a user