DEV Community

The Silent Partner
The Silent Partner

Posted on

First Update

This project is going to force me to come to terms with the meaning of the phrase "Perfect is the enemy of done" because boiii.

So in my mini update I said maybe 2 weeks to get an MVP locally running (not in those exact words but ya) well I definitely over estimated myself, my time and my addiction to trying to solve difficult problems.

First the validation thing that I said I would leave till later, well i couldnt help but keep trying to take a stab at it. Trying to get it working rather than focusing my time else where. I think I am looking for the perfect solution that isnt overly complicated and in JS there isnt an easy way to find it. I think I will do a separate post to rubber duck my problems with what I want and what I have tried.

Second is when you work with ruby on the regular then you move back to JS for a while you get disappointed with the missing methods that are common in ruby. For example I need to make an array of a random selection of values from a much larger array if I was to write this in ruby it would be something like this:

orginal_array = [1,2,3,4,5,6,7,8,9,0]
new_array = original_array.shuffle
new_array.first(4)
Enter fullscreen mode Exit fullscreen mode

or like this

original_array = [1,2,3,4,5,6,7,8,9,0]
new_array = original_array.shuffle.take(8)
Enter fullscreen mode Exit fullscreen mode

or better yet

original_array = [1,2,4,5,6,7,8,9,0]
new_array = original_array.sample(4)
Enter fullscreen mode Exit fullscreen mode

I know they work I just tested them to make sure.

Where as in JS to try and replicate these methods this is what I had to come up with:

$sel = []
let originalArray = [1,2,3,4,5,6,7,8,9,0]
function randomNumbers() {
let temp = []
let pool = []

originArray.forEach((element) => {
      for (let i = 0; i < element[1]; i += 1) {
        pool.push(element[0]);
      }
    });
for (let i = 0; i < 9; i++) {
      // let random = Math.floor(Math.random())

      temp.push(pool[Math.floor(Math.random() * 98)]);
      $sel = temp;
    }
    console.log($sel);
    return;
  }
Enter fullscreen mode Exit fullscreen mode

Note: In my code the originalArray proper length is 98 that is why the random multiplier is so high

Now this definitely could just be a skill issue but from my searching there didn't seem to be a better way to do it (let me know in the comments). Going from Ruby back to this made my already not so fast coding shift down again in gear.

But anyways enough of that lets me just make a note on what I am happy about.

Progress is slow but continuing well. I will be looking at multiplayer within the next couple of days. Timer is done Game start condition is done. Points calculation not yet finished.

Top comments (0)