DEV Community

duccanhole
duccanhole

Posted on

5

code every day with me

--DAY 14--

Hi, I am going to make #100DaysOfCode Challenge. Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
Now let's solve problem today:

  • Problem: Pascal's Triangle
  • Detail: here
  • My solution (javascript):
var generate = function(n) {
    if(n==1) return [[1]];
    if(n==2) return [[1],[1,1]];
    let arr=[[1],[1,1]];
    for(let i=2;i<n;i++){
        arr[i]=[1];
        for(let j=1;j<i;j++){
            arr[i].push(arr[i-1][j-1]+arr[i-1][j]);
        }
        arr[i].push(1);
    }
    return arr;
};
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay