Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

287
Views
TypeScript: How to specify a reference column and copy its value to remaining columns?

I have a table that looks like this:

+-------+-------+-------+-------+-------+
| Week1 | Week2 | Week3 | Week4 | Week5 |
+-------+-------+-------+-------+-------+
| AAAAA | BBBBB | CCCCC | DDDDD | EEEEE |
+-------+-------+-------+-------+-------+

I would like to write a function that:

  • Input: (1) reference column name (2) a list of impacted column name
  • Output: impacted column values changed to the same as the reference column

For example: function(1,2) means: copy Week 1 value to Week 2

+-------+-------+-------+-------+-------+
| Week1 | Week2 | Week3 | Week4 | Week5 |
+-------+-------+-------+-------+-------+
| AAAAA | AAAAA | CCCCC | DDDDD | EEEEE |
+-------+-------+-------+-------+-------+

For another example:

function(1,[2,3]) means: copy Week 1 value to Week 2 and Week 3

+-------+-------+-------+-------+-------+
| Week1 | Week2 | Week3 | Week4 | Week5 |
+-------+-------+-------+-------+-------+
| AAAAA | AAAAA | AAAAA | DDDDD | EEEEE |
+-------+-------+-------+-------+-------+

For another example: function(4,[2,3,5]) means: copy Week 4 value to Week 2, Week 3, and Week 5

+-------+-------+-------+-------+-------+
| Week1 | Week2 | Week3 | Week4 | Week5 |
+-------+-------+-------+-------+-------+
| AAAAA | DDDDD | DDDDD | DDDDD | DDDDD |
+-------+-------+-------+-------+-------+

For another example: function(2,[1,3,5]) means: copy Week 2 value to Week 1, Week 3, and Week 5

+-------+-------+-------+-------+-------+
| Week1 | Week2 | Week3 | Week4 | Week5 |
+-------+-------+-------+-------+-------+
| BBBBB | BBBBB | BBBBB | DDDDD | BBBBB |
+-------+-------+-------+-------+-------+

There could be only 1 reference column, but there could be multiple impacted columns.

I am very new to TypeScript and can't wrap my head around on how to do this in TypeScript.

I am not sure if thinking this way makes sense:

  • Concatenate all of 5 Weeks' of value into a long string (25 digits)
  • Then I am able to have the index of each week (e.g. Week 1 value = str[0:4], Week 2 value = str[5:9] etc.)
  • Then just take the reference column value and replace to the impacted columns

Much appreciation for any help!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!