TZinovieva

Sum First and Last JS Fundamentals

Feb 6th, 2023
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sumFirstAndLast(input) {
  2.     let firstElement = Number(input[0]);
  3.     let lastElement = Number(input.pop());
  4.    
  5.     console.log(firstElement + lastElement);
  6. }
  7.  
  8. OR
  9.  
  10. function sumFirstAndLast(input) {
  11.     input = input.map(Number);
  12.     console.log(input[0] + input.pop());
  13. }
Advertisement
Add Comment
Please, Sign In to add comment