Advertisement
Guest User

Untitled

a guest
May 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. /* Reversing an array */
  2. function reverseArray(array){
  3. let reArray = [];
  4. while(array.length){
  5. reArray.push(array.pop());
  6. }
  7. return reArray;
  8. }
  9.  
  10. function reverseArrayInPlace(array){
  11. for(let i=0, len=array.length; i<Math.floor(len/2); i++){
  12. [array[i], array[array.length-1-i]] = [array[array.length-1-i], array[i]];
  13. }
  14. return array;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement