<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Typescrypt array help.]]></title><description><![CDATA[<p dir="auto">Parent array</p>
<pre><code>let activity = [
{ startDate: 2020-10-21, endDate: 2020-10-22, steps: 100, distance: 100 }, 
{ startDate: 2020-10-22, endDate: 2020-10-23, steps: 100, distance: 100 }
]
</code></pre>
<p dir="auto">මෙන්න මේ උඩ තියෙන Array එකට පහත දක්වලා තියෙන arrays 2න් ඩේටා ගන්න ඕන. මේ උඩ තියෙන ඇරේ එකේ startDate, endDate වලට සමාන අගයන් තියෙන පහල තියෙන ඇරෙස් වලින් ඩේටා අරගෙන ෆිල් කරවන්න ඕන. මේක කොහොමද කරගන්නෙ?</p>
<ol>
<li></li>
</ol>
<pre><code>let steps= [
{ startDate: 2020-10-21, endDate: 2020-10-22, steps: 100 }, 
{ startDate: 2020-10-22, endDate: 2020-10-23, steps: 100 }
]
</code></pre>
<ol start="2">
<li></li>
</ol>
<pre><code>let activity = [
 { startDate: 2020-10-21, endDate: 2020-10-22, distance: 100 }, 
{ startDate: 2020-10-22, endDate: 2020-10-23, distance: 100 }
                          ]
</code></pre>
<p dir="auto">ස්තූතියි</p>
]]></description><link>https://lankadevelopers.lk/topic/794/typescrypt-array-help</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Jul 2026 10:40:47 GMT</lastBuildDate><atom:link href="https://lankadevelopers.lk/topic/794.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 08 Feb 2021 18:22:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Typescrypt array help. on Sun, 14 Feb 2021 18:47:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/1622">@nb</a> said in <a href="/post/4349">Typescrypt array help.</a>:</p>
<blockquote>
<pre><code>                                                                                                                                                                            distance: Number                                                                                                                                                                            }                                                                                                                                                                                                                                                                                                                                                         let steps: Array&lt;Steps&gt; = [                                                                                                                                                                                { startDate: '2020-10-21', endDate: '2020-10-22', steps: 101 },                                                                                                                                                                                 { startDate: '2020-10-22', endDate: '2020-10-23', steps: 102 },                                                                                                                                                                                { startDate: '2020-10-24', endDate: '2020-10-25', steps: 103 }                                                                                                                                                                            ];                                                                                                                                                                                                                                                                                                                                                         let activity: Array&lt;Distance&gt; = [                                                                                                                                                                                { startDate: '2020-10-21', endDate: '2020-10-22', distance: 101 },                                                                                                                                                                                 { startDate: '2020-10-22', endDate: '2020-10-23', distance: 102 },                                                                                                                                                                                { startDate: '2020-10-26', endDate: '2020-10-26', distance: 103 }                                                                                                                                                                            ];                                                                                                                                                                                                                                                                                                                                                         function join&lt;L extends Record&lt;string,any&gt;, R extends Record&lt;string,any&gt;&gt;(left: Array&lt;L&gt;,  right: Array&lt;R&gt;,  by: Array&lt;string&gt;) {                                                                                                                                                                                const joined: Array&lt;L&amp;R&gt; = [];                                                                                                                                                                                                                                                                                                                                                             for (let l of left) {                                                                                                                                                                                    const fromRight = right.find(r =&gt; by.every((curr) =&gt; (r[curr] == l[curr]), true))                                                                                                                                                                                    if (fromRight === undefined)                                                                                                                                                                                        continue;                                                                                                                                                                                    joined.push({ ...fromRight, ...l})                                                                                                                                                                                }                                                                                                                                                                                                                                                                                                                                                             return joined;                                                                                                                                                                            }                                                                                                                                                                                                                                                                                                                                                         console.log(join(steps, activity, ['startDate', 'endDate']))                                                                                                                                                                            /*                                                                                                                                                                            [LOG]: [{                                                                                                                                                                              "startDate": "2020-10-21",                                                                                                                                                                              "endDate": "2020-10-22",                                                                                                                                                                              "distance": 101,                                                                                                                                                                              "steps": 101                                                                                                                                                                            }, {                                                                                                                                                                              "startDate": "2020-10-22",                                                                                                                                                                              "endDate": "2020-10-23",                                                                                                                                                                              "distance": 102,                                                                                                                                                                              "steps": 102                                                                                                                                                                            }]                                                                                                                                                                             */                                            
</code></pre>
</blockquote>
<p dir="auto">Thanx Brother. man try karala balannam meka</p>
]]></description><link>https://lankadevelopers.lk/post/4350</link><guid isPermaLink="true">https://lankadevelopers.lk/post/4350</guid><dc:creator><![CDATA[oditha]]></dc:creator><pubDate>Sun, 14 Feb 2021 18:47:40 GMT</pubDate></item><item><title><![CDATA[Reply to Typescrypt array help. on Thu, 11 Feb 2021 07:19:32 GMT]]></title><description><![CDATA[<p dir="auto">මේ වැඩේ හිතුවට වඩා සංකීර්ණයි. කොහොම හරි O(n2) solution එකක් හොයා ගත්තා.</p>
<pre><code>interface Steps extends Record&lt;string, any&gt; { 
    startDate: String; 
    endDate: String; 
    steps: Number
}

interface Distance extends Record&lt;string, any&gt; { 
    startDate: String; 
    endDate: String; 
    distance: Number
}

let steps: Array&lt;Steps&gt; = [
    { startDate: '2020-10-21', endDate: '2020-10-22', steps: 101 }, 
    { startDate: '2020-10-22', endDate: '2020-10-23', steps: 102 },
    { startDate: '2020-10-24', endDate: '2020-10-25', steps: 103 }
];

let activity: Array&lt;Distance&gt; = [
    { startDate: '2020-10-21', endDate: '2020-10-22', distance: 101 }, 
    { startDate: '2020-10-22', endDate: '2020-10-23', distance: 102 },
    { startDate: '2020-10-26', endDate: '2020-10-26', distance: 103 }
];

function join&lt;L extends Record&lt;string,any&gt;, R extends Record&lt;string,any&gt;&gt;(left: Array&lt;L&gt;,  right: Array&lt;R&gt;,  by: Array&lt;string&gt;) {
    const joined: Array&lt;L&amp;R&gt; = [];

    for (let l of left) {
        const fromRight = right.find(r =&gt; by.every((curr) =&gt; (r[curr] == l[curr]), true))
        if (fromRight === undefined)
            continue;
        joined.push({ ...fromRight, ...l})
    }

    return joined;
}

console.log(join(steps, activity, ['startDate', 'endDate']))
/*
[LOG]: [{
  "startDate": "2020-10-21",
  "endDate": "2020-10-22",
  "distance": 101,
  "steps": 101
}, {
  "startDate": "2020-10-22",
  "endDate": "2020-10-23",
  "distance": 102,
  "steps": 102
}] 
*/
</code></pre>
<p dir="auto">Types දාපු හැටි හරිද දන්නෑ. logic එක නං හරි.</p>
<p dir="auto"><a href="https://www.typescriptlang.org/play?ssl=42&amp;ssc=61&amp;pln=1&amp;pc=1#code/JYOwLgpgTgZghgYwgAgMqQA4GdkQB6QgAmOAShAgPZREA8WYUoA5gDTJwgCeAfMgN7IAUMlHIGcKGAAicSAC40jFgG5hY3MVkKlTEMzUixDCNkUA5AK4BbAEbQhAXyFDQkWIhTTgEkElwEEMRkFNR0DHpsHNx8gkaiElLaEIrokYYaQUTJqcr6GWJEPmCcSBY29lBOLgA2EGDimFiKAIJQUHBctOimWHwAvMgA2vECjZIycinIAOQATAAMiwC0AIwLy3OrM+xZObOLK+ubczuNvYrrq8iO7KOCiZM680sbx3Onu1pTii9HG3MAMxnExmZDrOY3Vj3cZJH4HV5rAEAFjOe3hfzeAIArCCmpcFoCbkIALoqWr1DgIMDAABuwDAXFa7U6tG8viQA2GMMe+0xSM22y+2QxhyxJzORQ50yuUPUYgeJThzzFAo+aO+KsR72B7ClJT8MqWUJ5Sqe0357wAbBqRVr-psbXriqUjUTnGSXDBLH4aZQQMgAFaUUC0AAyAUIJGQ5CoNHoeSinF47FIkayITj4UT7GTPB4AApRnUYGBmR0umGeHcNExmAALMvINoV2ikavy0S2JnNlldCIsHhCACUAlGVBADCDIZAECI5dZYYAZO3kIMhp7RjBqMgC3UGjVkJQYMgS2BR-xRhoJ1OYFBKNZSMAGw1BnXGwA6GCgIgFqBrvhuw-CBaWgLgCwLBBLHaUd+j4P8hig9oSTXQYakQ6CoBJYd2EYSwIGHYcrzEYATwLO8HyfF9UMGH0iAgb9ZyIIiNFYsQJxpEB8PJNjRGDUA5w-DBLCwesC0ED9JIox9n0bdhJI-GpHBYsRnFGKB6mggN+KY8k1JvSg6kUyhmALHSC1BLBc2pOkGS4dghhmXkpjOGZ0UgGZsOHIA" target="_blank" rel="noopener noreferrer nofollow ugc">Playground link</a></p>
]]></description><link>https://lankadevelopers.lk/post/4349</link><guid isPermaLink="true">https://lankadevelopers.lk/post/4349</guid><dc:creator><![CDATA[nb]]></dc:creator><pubDate>Thu, 11 Feb 2021 07:19:32 GMT</pubDate></item></channel></rss>