locked
repeat data depending on date between RRS feed

  • Question

  • User-1634604574 posted

    i have this array with these two textboxes 

    <input type="text" value="2019-01-01">
    <input type="text" value="2019-01-10">
    
    <script>
    
    var employee=['a','b','c']
    
    </script>
    
    i want to create table like this 
    
    <table>
    <tr><th>employee</th><th>date</th></tr>
    <tr><td>a</td><td>2019-01-01</td></tr>
    <tr><td>a</td><td>2019-01-02</td></tr>
    <tr><td>a</td><td>2019-01-03</td></tr>
    <tr><td>a</td><td>2019-01-04</td></tr>
    <tr><td>a</td><td>2019-01-05</td></tr>
    <tr><td>a</td><td>2019-01-06</td></tr>
    <tr><td>a</td><td>2019-01-07</td></tr>
    <tr><td>a</td><td>2019-01-08</td></tr>
    <tr><td>a</td><td>2019-01-09</td></tr>
    <tr><td>a</td><td>2019-01-10</td></tr>
    
    <tr><td>b</td><td>2019-01-01</td></tr>
    <tr><td>b</td><td>2019-01-02</td></tr>
    <tr><td>b</td><td>2019-01-03</td></tr>
    <tr><td>b</td><td>2019-01-04</td></tr>
    <tr><td>b</td><td>2019-01-05</td></tr>
    <tr><td>b</td><td>2019-01-06</td></tr>
    <tr><td>b</td><td>2019-01-07</td></tr>
    <tr><td>b</td><td>2019-01-08</td></tr>
    <tr><td>b</td><td>2019-01-09</td></tr>
    <tr><td>b</td><td>2019-01-10</td></tr>
    
    <tr><td>c</td><td>2019-01-01</td></tr>
    <tr><td>c</td><td>2019-01-02</td></tr>
    <tr><td>c</td><td>2019-01-03</td></tr>
    <tr><td>c</td><td>2019-01-04</td></tr>
    <tr><td>c</td><td>2019-01-05</td></tr>
    <tr><td>c</td><td>2019-01-06</td></tr>
    <tr><td>c</td><td>2019-01-07</td></tr>
    <tr><td>c</td><td>2019-01-08</td></tr>
    <tr><td>c</td><td>2019-01-09</td></tr>
    <tr><td>c</td><td>2019-01-10</td></tr>
    </table>
    



    Wednesday, July 24, 2019 6:05 PM

Answers

  • User475983607 posted

    i have this code i want to sort that array 

    <script>
    
    arr=['a','b']
    const makeRepeated = (arr, repeats) =>
      Array.from({ length: repeats }, () => arr).flat();
      
      var arr2=[]
      
      arr2.push(makeRepeated(arr, 4))
      var c=arr2.sort()
       
     
      
      alert(c)
      
    
    </script>

    but is not sorting i don't know where is my error

    The result is an array of arrays.

    var c=arr2[0].sort()

    Make sure when you copy code from the internet you do a little research to make sure you understand how it works.  Also use the browser's dev tools when debugging JavaScript and stop using alert();

    arr=['a','b']
    const makeRepeated = (arr, repeats) => Array.from({ length: repeats }, () => arr).flat();
    var result = makeRepeated(arr, 4).sort();
    console.log(result); //Dev tools Console

    Results

    ["a", "a", "a", "a", "b", "b", "b", "b"]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 24, 2019 8:59 PM

All replies

  • User475983607 posted

    Share your code and explain where you need assistance.

    Wednesday, July 24, 2019 6:10 PM
  • User-1634604574 posted

    i cannot create that table code for creating that table

    Wednesday, July 24, 2019 6:15 PM
  • User475983607 posted

    i cannot create that table code for creating that table

    Please share the code that you have written up to this point.  Provide the steps to reproduce the issue creating the table.  Explain clearly the expected results and actual results of running your code.

    Wednesday, July 24, 2019 6:28 PM
  • User-1634604574 posted

    i didn't write any code for that

    Wednesday, July 24, 2019 6:34 PM
  • User475983607 posted

    i didn't write any code for that

    You should at least try.  There are two main parts to this programming problem.  Generating the dates and building two loops to populate the HTML table.

    Wednesday, July 24, 2019 6:53 PM
  • User-1634604574 posted

    i have this code i want to sort that array 

    <script>
    
    arr=['a','b']
    const makeRepeated = (arr, repeats) =>
      Array.from({ length: repeats }, () => arr).flat();
      
      var arr2=[]
      
      arr2.push(makeRepeated(arr, 4))
      var c=arr2.sort()
       
     
      
      alert(c)
      
    
    </script>

    but is not sorting i don't know where is my error

    Wednesday, July 24, 2019 7:15 PM
  • User475983607 posted

    i have this code i want to sort that array 

    <script>
    
    arr=['a','b']
    const makeRepeated = (arr, repeats) =>
      Array.from({ length: repeats }, () => arr).flat();
      
      var arr2=[]
      
      arr2.push(makeRepeated(arr, 4))
      var c=arr2.sort()
       
     
      
      alert(c)
      
    
    </script>

    but is not sorting i don't know where is my error

    The result is an array of arrays.

    var c=arr2[0].sort()

    Make sure when you copy code from the internet you do a little research to make sure you understand how it works.  Also use the browser's dev tools when debugging JavaScript and stop using alert();

    arr=['a','b']
    const makeRepeated = (arr, repeats) => Array.from({ length: repeats }, () => arr).flat();
    var result = makeRepeated(arr, 4).sort();
    console.log(result); //Dev tools Console

    Results

    ["a", "a", "a", "a", "b", "b", "b", "b"]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 24, 2019 8:59 PM