Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Closed
AlixdeR wants to merge 1 commit intoironhack-labs:masterironhack-labs/lab-javascript-basic-algorithms:masterfrom
AlixdeR:masterAlixdeR/lab-javascript-basic-algorithms:masterCopy head branch name to clipboard
Closed

[PAR WDFT] Paul C & Alix - ongoing#650
AlixdeR wants to merge 1 commit intoironhack-labs:masterironhack-labs/lab-javascript-basic-algorithms:masterfrom
AlixdeR:masterAlixdeR/lab-javascript-basic-algorithms:masterCopy head branch name to clipboard

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.