<script>
const checkDogs = function(arr1, arr2){
const arr1Shallow = arr1.slice();
arr1Shallow.splice(0,1);
arr1Shallow.splice(-2);
const dogs = arr1Shallow.concat(arr2);
dogs.forEach(function(age, i){
const type = age >= 3 ? `Dog number ${i+1} is an adult, and is ${age} years old`:`Dog number ${i+1} is still a puppy`;
console.log(type);
})
}
checkDogs([3,5,2,12,7],[4,1,15,8,3]);
// LECTURES
const currencies = new Map([
['USD', 'United States dollar'],
['EUR', 'Euro'],
['GBP', 'Pound sterling'],
]);
const movements = [200, 450, -400, 3000, -650, -130, 70, 1300];
for (const [i, movement] of movements.entries()){
if (movement > 0){
console.log(`${i + 0}:You deposit ${movement}`);
}else{
console.log(`${i + 0}:You withdrew ${Math.abs(movement)}`);
}
} //This is how you get index from forOf Loop --> const [i, movement] of movement.entries()
//Use forOf Loop if you need to break up a loop
//forEach(function())Method
// Easier to get current index from forEach Method
// forEach(function(variable, index, array){}) --Parameters name doesnt affect, only the sequence affect the index
/*movements.forEach(function(movement, index, array){
if (movement > 0){
console.log(`${index + 0}:You deposit ${movement}`);
}else{
console.log(`${index + 0}:You withdrew ${Math.abs(movement)}`);
}
})*/
//Map is something similar to forEach & forOf
const myrToTwd = 6.5;
const convert = movements.map(function(mov){
return mov * myrToTwd;
})
console.log(convert);
//writing using arrow function
const converts = movements.map(mov=> mov * myrToTwd;)
//using forOf loop will need to manually create array to push
const forOfMyrToTwd = [];//manually create array
for (const mov of movements){
forOfMyrToTwd.push(mov*myrToTwd)
}
</script>