What is intuition behind calc GCD of the number of compute LCM

Tell us what’s happening:
What is intuition behind calc GCD of the number of compute LCM .?

  1. One is reduced complexity.
    is there anything else?

Your code so far


function smallestCommons(arr) {
return arr;
}


smallestCommons([1,5]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36.

Challenge: Smallest Common Multiple

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple

I’m not sure I understand your question. Could you please elaborate?

I have just started programming, how to know that with the help of GCD() we can calc the LCM easily.?(What the thought process of coming up with this kinda solution) Before looking at the solution i didn’t had clue what to do, i was stuck.

I only know it because Wikipedia has a pretty good explanation. This is something that was figured out by people who are better at math than I will ever be. As a programmer with math literacy, what I was able to do was research whether there was a mathematical solution and then turn that math into functioning code. Sometimes that’s just how it goes.

1 Like

Wikipedia was how I worked it out too. You need to learn to ask good initial questions (not necessarily, or even often, to a person, and often just to yourself), then take the answers to them and either use them, or ask further good questions based on them. Thats…not easy at first. But knowledge should build on itself.

So questioning generally starts with Google nowadays. Before the internet democratised knowledge it would have been somewhere where the knowledge was stored, eg a library.

What you’re talking about here has been known for hundreds of years. You don’t need to figure out the basic principles yourself – nothing would ever get done if everything was built from first principles. It’s just that you need to get better at locating that knowledge, and then bookmarking it in your memory. And you then just need to be able to convert the solution to code (which again, may not be easy at first).

2 Likes

Thank @ArielLeslie @DanCouper. Sometimes math confuses me

1 Like