Skip to content

[PAR WDFT] Paul C & Alix - ongoing #650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

AlixdeR
Copy link

@AlixdeR AlixdeR commented Jan 9, 2020

done

@Jepassaispar Jepassaispar changed the title [PAR WDFT] Paul C & Alix [PAR WDFT] Paul C & Alix - ongoing Jan 9, 2020
@Jepassaispar
Copy link

Well done guys !
For your iteration 4 (1/2), when you are starting to do a lot of if else statements, it means that there might be a better solution somewhere, if you look up on google, there is the localCompare function that is a built in function that compare 2 strings and return the first one :

if (hacker2.localeCompare(hacker1)) { console.log("The driver's name goes first."); } else if (hacker1.localeCompare(hacker2)){ console.log("Yo, the navigator goes first definitely."); } else { console.log("What?! You both have the same name?"); }

This is one of the many answers available, don't hesitate to check online. Anyway don't worry, here is what I did last cohort :

function whichNameGoesFirst() {
  if (hacker1Length < hacker2Length) {
    for (let i = 0; i < hacker1Length; i++)
      if (hacker1[i] < hacker2[i] || (hacker1[i] = hacker2[i])) {
        console.log("The driver's name goes first.");
        break;
      } else if (hacker1[i] > hacker2[i]) {
        console.log("Yo, the navigator goes first definitely.");
        break;
      }
  } else if (hacker1Length > hacker2Length) {
    for (let i = 0; i < hacker1Length; i++)
      if (hacker1[i] > hacker2[i] || (hacker1[i] = hacker2[i])) {
        console.log("Yo, the navigator goes first definitely.");
        break;
      } else if (hacker1[i] < hacker2[i]) {
        console.log("The driver's name goes first.");
        break;
      }
  } else if (hacker1Length === hacker2Length) {
    for (let i = 0; i < hacker1Length; i++)
      if (hacker1[i] < hacker2[i]) {
        console.log("The driver's name goes first.");
        break;
      } else if (hacker1[i] > hacker2[i]) {
        console.log("Yo, the navigator goes first definitely.");
        break;
      } else {
        console.log("You have the same name !");
        break;
      }
  }
}

whichNameGoesFirst();

So I really can't blame you ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy