How to generate number pattern inside loop?How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do I redirect to another webpage?JavaScript closure inside loops – simple practical exampleGenerating random whole numbers in JavaScript in a specific range?How to check whether a string contains a substring in JavaScript?Loop through an array in JavaScriptGenerate random number between two numbers in JavaScriptHow do I remove a particular element from an array in JavaScript?

Why Shazam when there is already Superman?

Not using 's' for he/she/it

Count the occurrence of each unique word in the file

Is it safe to use olive oil to clean the ear wax?

Is it possible to have a strip of cold climate in the middle of a planet?

Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

Is it better practice to read straight from sheet music rather than memorize it?

Why electric field inside a cavity of a non-conducting sphere not zero?

How could a planet have erratic days?

What if a revenant (monster) gains fire resistance?

copy and scale one figure (wheel)

If a character has darkvision, can they see through an area of nonmagical darkness filled with lightly obscuring gas?

Aragorn's "guise" in the Orthanc Stone

If infinitesimal transformations commute why dont the generators of the Lorentz group commute?

250 Floor Tower

Energy measurement from position eigenstate

Redundant comparison & "if" before assignment

Offered money to buy a house, seller is asking for more to cover gap between their listing and mortgage owed

Travelling outside the UK without a passport

"Spoil" vs "Ruin"

Is there a single word describing earning money through any means?

The IT department bottlenecks progress. How should I handle this?

Does a 'pending' US visa application constitute a denial?



How to generate number pattern inside loop?


How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do I redirect to another webpage?JavaScript closure inside loops – simple practical exampleGenerating random whole numbers in JavaScript in a specific range?How to check whether a string contains a substring in JavaScript?Loop through an array in JavaScriptGenerate random number between two numbers in JavaScriptHow do I remove a particular element from an array in JavaScript?













2















I have the following code:






for ( let i = 1; i <= 12; i++ ) 
console.log(i % 4);





It generates the output:



1
2
3
0
1
2
3
0
1
2
3
0


I'm trying to change the pattern (i % 4) so it gives me the following sequence instead:



1
1
1
1
2
2
2
2
3
3
3
3


I don't want to use a variable for it, just change the pattern inside the console.log to a good one that doesn't rely on for example multiple tenary operators.



It should keep increasing 1 every 4 iterations and work for more than 12 iterations.










share|improve this question




























    2















    I have the following code:






    for ( let i = 1; i <= 12; i++ ) 
    console.log(i % 4);





    It generates the output:



    1
    2
    3
    0
    1
    2
    3
    0
    1
    2
    3
    0


    I'm trying to change the pattern (i % 4) so it gives me the following sequence instead:



    1
    1
    1
    1
    2
    2
    2
    2
    3
    3
    3
    3


    I don't want to use a variable for it, just change the pattern inside the console.log to a good one that doesn't rely on for example multiple tenary operators.



    It should keep increasing 1 every 4 iterations and work for more than 12 iterations.










    share|improve this question


























      2












      2








      2








      I have the following code:






      for ( let i = 1; i <= 12; i++ ) 
      console.log(i % 4);





      It generates the output:



      1
      2
      3
      0
      1
      2
      3
      0
      1
      2
      3
      0


      I'm trying to change the pattern (i % 4) so it gives me the following sequence instead:



      1
      1
      1
      1
      2
      2
      2
      2
      3
      3
      3
      3


      I don't want to use a variable for it, just change the pattern inside the console.log to a good one that doesn't rely on for example multiple tenary operators.



      It should keep increasing 1 every 4 iterations and work for more than 12 iterations.










      share|improve this question
















      I have the following code:






      for ( let i = 1; i <= 12; i++ ) 
      console.log(i % 4);





      It generates the output:



      1
      2
      3
      0
      1
      2
      3
      0
      1
      2
      3
      0


      I'm trying to change the pattern (i % 4) so it gives me the following sequence instead:



      1
      1
      1
      1
      2
      2
      2
      2
      3
      3
      3
      3


      I don't want to use a variable for it, just change the pattern inside the console.log to a good one that doesn't rely on for example multiple tenary operators.



      It should keep increasing 1 every 4 iterations and work for more than 12 iterations.






      for ( let i = 1; i <= 12; i++ ) 
      console.log(i % 4);





      for ( let i = 1; i <= 12; i++ ) 
      console.log(i % 4);






      javascript for-loop






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago







      user7393973

















      asked 2 days ago









      user7393973user7393973

      979532




      979532






















          1 Answer
          1






          active

          oldest

          votes


















          7














          You could divide the value by 4 and take the value with Math.ceil for the next integer number.






          for ( let i = 1; i <= 12; i++ ) 
          console.log(Math.ceil(i / 4));








          share|improve this answer























          • Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.

            – user7393973
            2 days ago










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281317%2fhow-to-generate-number-pattern-inside-loop%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          7














          You could divide the value by 4 and take the value with Math.ceil for the next integer number.






          for ( let i = 1; i <= 12; i++ ) 
          console.log(Math.ceil(i / 4));








          share|improve this answer























          • Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.

            – user7393973
            2 days ago















          7














          You could divide the value by 4 and take the value with Math.ceil for the next integer number.






          for ( let i = 1; i <= 12; i++ ) 
          console.log(Math.ceil(i / 4));








          share|improve this answer























          • Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.

            – user7393973
            2 days ago













          7












          7








          7







          You could divide the value by 4 and take the value with Math.ceil for the next integer number.






          for ( let i = 1; i <= 12; i++ ) 
          console.log(Math.ceil(i / 4));








          share|improve this answer













          You could divide the value by 4 and take the value with Math.ceil for the next integer number.






          for ( let i = 1; i <= 12; i++ ) 
          console.log(Math.ceil(i / 4));








          for ( let i = 1; i <= 12; i++ ) 
          console.log(Math.ceil(i / 4));





          for ( let i = 1; i <= 12; i++ ) 
          console.log(Math.ceil(i / 4));






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 days ago









          Nina ScholzNina Scholz

          193k15105177




          193k15105177












          • Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.

            – user7393973
            2 days ago

















          • Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.

            – user7393973
            2 days ago
















          Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.

          – user7393973
          2 days ago





          Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.

          – user7393973
          2 days ago



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281317%2fhow-to-generate-number-pattern-inside-loop%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현