DEV Community

Discussion on: Deli Counter Challenge

Collapse
 
gregggarrison profile image
gregggarrison

Can you elaborate on output = output.slice(0, -2)? Why would we want to remove the last 2 items?

Collapse
 
miaonanlin profile image
miaonanlin

A simple example
var fruits = ["Banana", "Orange", "Apple", "Mango"];
the output of fruits.slice(0,-2) is ["Banana", "Orange"], which is the first two items in the list.
however, the output of fruits.slice(-2) is ["Apple", "Mango"] , which is the last two items in the list.
.