---
# System prepended metadata

title: DRYKISS

---

# DRYKISS

```javascript=
import promptSync from 'prompt-sync';

const productOfList = (list: number[]) => {
  return list.reduce((a, b) => {a*b}, 1);
}

/**
 * Given an array of n integers, calculate the minimum, maximum, and the
 * product of the first n-1 numbers and last n-1 numbers.
 */
function drykiss(myList: number[]) {
  // Brilliant!
  const myMin = Math.min(...myList);
  const myMax = Math.max(...myList);
  
  // Bewildering!
  const prodHead = productOfList(myList.slice(0, 4));
  const prodTail = productOfList(myList.slice(1, 5));
     
  return [myMin, myMax, prodHead, prodTail];
}

const prompt = promptSync();
const a = parseInt(prompt('Enter a: '));
const b = parseInt(prompt('Enter b: '));
const c = parseInt(prompt('Enter c: '));
const d = parseInt(prompt('Enter d: '));
const e = parseInt(prompt('Enter e: '));
const myList = [a, b, c, d, e];
const result = drykiss(myList);
// or...
// Astonishing!
const [myMin, myMax, prodHead, prodTail] = drykiss(myList);


console.log('Minimum:');
console.log(`${result[0]}`);
console.log('Maximum:');
console.log(`${result[1]}`);
console.log('Product of first 4 numbers:');
console.log(`${result[2]}`);
console.log('Product of last 4 numbers');
console.log(`${result[3]}`);
```

# Code review
## Sample:
```javascript=

// Interfaces
interface pet {
    animal: string, name: string, age: number
}

interface Person {
    name: string,
    age: number,
    occupation: string,
    pets: pet[];
    friends: Person[];
    favouriteColour?: string
}


// MAIN FUNCTION HERE
const kayla = createPerson("kayla", 19, "student", [ { animal: "cat", name: "rosy", age: 14 }, { animal: "dog", name: "mimi", age: 8 } ]);
const dave = createPerson("dave", 20, "electrician", []);
AddPet(dave, "turtle", "geoff", 2);
addFriend(kayla, dave);
const kayla_and_her_friends_pets = friends_combined_pets(kayla);
printPets(kayla_and_her_friends_pets);


// Other functions

// Create a person with a name, age, occupation and pets
function createPerson(name: string, age: number, occupation: string, pets: pet[]) {
    let person: Person = {
        name, age, occupation, pets: [], friends: []
    }
    person = createPetsArrayForPerson(pets, person);
    return person;
}

// helper function for createPerson
function createPetsArrayForPerson(pets: pet[], person: Person) {
    person.pets = pets;
    return person;
}

// Add a pet to a given person
function AddPet(person: Person, animal: string, name: string, age: number) {
    person.pets[person.pets.length] = { animal, name, age};
}

// Print all the pets belonging to a person
function printPets(pets: pet[]) {
    const length = pets.length;
    console.log("[");
    for (let i = 0; i < length; i++) {
        console.log(pets[i]);
    }
    console.log("]");
}


// Add a person (who has already been created) as a friend to a given person
function addFriend(person: Person, friend: Person) {
    if (person.friends.find(x => x === friend)) { return; }
    else {person.friends.push(friend);}
}

// Given a person, return an array with the names of their and all their friend's pets
function friends_combined_pets(person: Person) {
    let length = person.pets.length;
    let combined_pet_array: pet[] = new Array(length);
    combined_pet_array = person.pets;
    
    let petTotal = combined_pet_array.length;
    for (const friend of person.friends) {
    combined_pet_array = combined_pet_array.concat(friend.pets);
    petTotal += friend.pets.length;
    }

    return combined_pet_array;
}
```
## List some improvements that can be made!

### AERO
-

### BOOST
- 

### CRUNCHIE
-

### DREAM
- printPets -> use forEach
- friend_combined_pets -> use forEach / reduce

### EGGS
-