Skip to content

Bad examples leads to bad developers #1

@sirian

Description

@sirian

1. Destructive assignment in this simple case?

 function resetBoard() {
    [hasFlippedCard, lockBoard] = [false, false];
    [firstCard, secondCard] = [null, null];
  }

Easily replaces with

 function resetBoard() {
    hasFlippedCard =  lockBoard = false;
    firstCard = secondCard = null
  }

2. Shuffle is incorrect

Code flow: shuffle is not uniform

Try to count how often vue turns out on top-left card

Code style

(function shuffle() {
    cards.forEach(card => {
      let ramdomPos = Math.floor(Math.random() * 12);
      card.style.order = ramdomPos;
    });
  })();

let should be replaced with const
12 should be replaced with cards.length
moreover why you use IIFE here? you could simply write

// shuffle elements
cards.forEach(card => {
    const ramdomPos = Math.floor(Math.random() * cards.length); 
    card.style.order = ramdomPos;
});

3. It is a de-facto standard to use brackets in if statements (even in one-liners)

if (lockBoard) {return;}
if (this === firstCard) {return;}

And there are plenty more...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions