Google News
logo
CoffeeScript - Interview Questions
Give an example to demonstrate the use of splats with tailing argument in CoffeeScript. Also, explain.
The splats with tailing argument refer to the argument placed after the splat argument.
 
Example :
indian_team = (first, second, others...., last) ->  
  Captain = first  
  WiseCaptain = second  
  team  = others  
  Wicketkeeper =last  
  console.log "Captain: " +Captain  
  console.log "Wise captain: " +WiseCaptain  
  console.log "Wicket keeper is:"+last  
  console.log "Other team members: " +team    
    
squad = [  
   "Mahendra Singh Dhoni"  
   "Virat Kohli"  
   "Shikhar Dhawan"  
   "Rohit Sharma"     
   "Gurkeerat Singh Mann"  
   "Rishi Dhawan"  
   "R Ashwin"  
   "Ravindra Jadeja"  
   "Axar Patel"  
   "Jasprit Bumrah"  
   "Umesh Yadav"  
   "Harbhajan Singh"  
   "Ashish Nehra"  
   "Hardik Pandya"  
   "Suresh Raina"  
   "Yuvraj Singh"  
   "Ajinkya Rahane"  
 ]​
  
In the above example of using tailing with splats, we have placed an additional argument to the argument list of the indian_team function.
Advertisement