const bankruptcy = () => { console.log("I declare bankruptcy!"); };

kevin klatman - Aug 2 - - Dev Community

For the first two months of my programming journey (so up until about two weeks ago), I thought Java was just short for JavaScript. Thinking I was in the know, I walked around for two months referring to JavaScript as "Java" for short, only to find out from a seasoned programmer that Java and JavaScript are two separate languages. What?! How embarrassing...

I only preface the post this way so that any potential reader can understand the level I'm operating on when I say writing this code:

function hasTargetSum(array, target) {
  for (let i = 0; i < array.length; i++) {
    for (let j = i + 1; j < array.length; j++) {
      if (array[i] + array[j] === target) {
        return true;
      }
    }
  }
  return false;
}
Enter fullscreen mode Exit fullscreen mode

is the crowning achievement of my coding career thus far (well it was when I wrote it anyway(one week ago-ish)). It's a function that returns true if the sum of any two numbers in an array add up to a target number using a nested loop.

It took me 5 hours to figure out what I thought was the right answer, but what I came to realize is that I hadn't found the "right" answer, I had only found "an" answer (and not a great answer at that, but I'm still proud of it).

In searching online I came to a sort of epiphany when I found a solution that reduces the time- complexity by recognizing that each number in the array has an implicit "pair number."

(For example if the target number is 10 and the first number of an array is 3, one would only need to search the rest of the array for a 7, the implicit "pair number" (because 3 + 7 = 10).

To me this was a creative and out of the box solution, which, as boring as it seems, changed the way I looked at programming. I had been looking at programming as a set of methods to mesmerize rather than as a language and a form of communication, and like in literal language, there are an indefinite amount of ways to convey what you want, some are better than others, but there is no single right way and there's plenty of room for various approaches and creativity.

I think anywayz, idk im only like 2 months in to programming.

. . .
Terabox Video Player