# Useful code clips

**URL:** <https://discourse.codecombat.com/t/useful-code-clips/30761>\
**Category:** Off-Topic\
**Created:** [September 30, 2021, 2:26am UTC](https://discourse.codecombat.com/t/useful-code-clips/30761 "2021-09-30T02:26:54Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![moonwatcher348](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/moonwatcher348/32/24126_2.png) [@moonwatcher348](https://discourse.codecombat.com/u/moonwatcher348)\
**Post date:** [September 30, 2021, 12:41pm UTC](https://discourse.codecombat.com/t/useful-code-clips/30761/5 "2021-09-30T12:41:23Z")

</div>

Is this better?

```javascript

hero.findOpponent = function () {
    for (let enemy of hero.findEnemies()) if (enemy.id.includes("Hero Placeholder")) return enemy;
    return undefined;
};
hero.findData = function (u) {
    let types = {assassin: "Ritic", intellectual: "Armando/Ned", knight: "Tharin", librarian: "Hushbaum", trapper: "Senick", sorcerer: "Pender", goliath: "Okar", duelist: "Alejandro", champion: "Ida", necromancer: "Nalfar", captain: "Anya", samurai: "Hattori", guardian: "Illia", pixie: "Zana"};
    let uData = {hero: types[u.type], type: null};
    if (!(uData.hero)) {
        switch (u.type) {
            case "forest-archer": return {hero: "Naria", type: "Ranger"};
            case "potion-master": return {hero: "Omarn", type: "Wizard"};
            case "master-wizard": return {hero: "Usara", type: "Wizard"};
        }
    }
    u = uData.hero;
    if (u === "Illia" || u === "Anya" || u === "Tharin" || u === "Okar" || u === "Alejandro" || u === "Ida" || u === "Hattori" || u === "Arryn" || u === "Gordon" || u === "Armando/Ned") uData.type = "Warrior";
    if (u === "Zana" || u === "Senick" || u === "Ritic" || u === "Amara") uData.type = "Ranger";
    if (u === "Hushbaum" || u === "Nalfar" || u === "Pender") uData.type = "Wizard";
    return uData;
};

```

Sorry about the delay 😅 I had to go to school…

---

_[View the full topic](https://discourse.codecombat.com/t/useful-code-clips/30761)._
