- Test your concepts of arrays by determining the location of an item in an array.
const indexOf = (arr, item) => {
// Your code here
}indexOf([1,2,3,4], 3) => 2
indexOf([5,6,7,8], 8) => 3| function showItems(arg1, arg2, arg3) { | |
| var arr = [arg2, arg3].concat(arg1); | |
| console.log(arr); | |
| } | |
| showItems(["dogs", "cats"], "turtles", "sharks"); | |
const indexOf = (arr, item) => {
// Your code here
}indexOf([1,2,3,4], 3) => 2
indexOf([5,6,7,8], 8) => 3| const getLocation = (city, country = "Italy", continent = "Europe") => | |
| console.log(continent, country, city); | |
| getLocation("Milan"); | |
| // Europe Italy Milan | |
| getLocation("Paris", "France"); | |
| // Europe France Paris | |
| const calculatePrice = ({ total, tax = 0.1, tip = 0.05 }) => | |
| total + total * tax + total * tip; |
| const person = { | |
| first: "Alberto", | |
| last: "Montalesi", | |
| }; | |
| const { first: firstName, last: lastName } = person; | |
| console.log(firstName, lastName); // console.log(firstName , lastName) | |
| // String Variable With Explicit Annotation | |
| let movieTitle: string = "Amadeus"; | |
| movieTitle = "Arrival"; | |
| movieTitle = 9; //This results in an error! | |
| movieTitle.toUpperCase(); | |
| // Number Variable with explicit annotation | |
| let numCatLives: number = 9; | |
| numCatLives += 1; | |
| numCatLives = "zero"; //Error! |