DEV Community

Discussion on: Let's Solve: Code Challenge - Picking Numbers

Collapse
 
nektro profile image
Meghan (she/her) • Edited

Great job on solving the problem!

Just some pointers for future reference:

  • new Array(100) is pretty wasteful, but I'll get back to this in a sec
  • map.fill(0) in your code isn't doing anything because you don't assign the return value back to map. Array.prototype.fill is not a modifier function
  • the entire first few lines could be condensed to
  let map = readLine().split(' ').map((x) => {
      return parseInt(x) + 1;
  });

JavaScript can be pretty confusing at time but I hope you stick around and again nice work :D

Collapse
 
ryhenness profile image
Ryan • Edited

Hey Sean, thanks for the response! I think for the way that I'm approaching the problem, that I actually need to initialize the array with 100 indices - otherwise, I couldn't map the keys to their array index positions. Also, I think fill does modify array values, as well as return the outcome of the fill. I tested that out on JSFiddle.

(Your avatar is dope btw. :))