Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Frontend Developers, what's happening?

views
     
TSsilverhawk
post Aug 26 2021, 07:28 PM, updated 7 months ago

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


There are some positions open in the company at the moment, so been doing some interviews. We have a warm-up question for the code whiteboarding session that goes like something like this

CODE

Write a function that takes an input number (e.g. 4) and prints:
1 2 3 4
1 2 3
1 2
1


and 90% of the candidates are failing this. All of the frontend candidates could not do this, even after some guidance. The opening is for a senior position with at least 5 years experience. While ability to answer the questions does not determine whether you get the offer or not, I find it quite odd that the warmup question is tripping people up.

Is anyone else facing this issue with their hiring? Should this level of problem solving ability not be expected of frontend devs?
malleus
post Aug 26 2021, 08:58 PM

Look at all my stars!!
*******
Senior Member
2,096 posts

Joined: Dec 2011
would have failed first year uni if not able to do this
FlierMate
post Aug 26 2021, 09:35 PM

On my way
****
Validating
515 posts

Joined: Nov 2020
It took me (as an old-timer) awhile to solve it. Initially I thought single loop was enough, but double loops are necessary. (See https://dotnetfiddle.net/6D78Dv, TQ for the exercise :=)

Maybe this question is too mind-boggling for frontend developers? rclxub.gif By all means, I am not qualified for web frontend tech stack either.


xhruso00
post Aug 26 2021, 09:43 PM

Getting Started
**
Junior Member
63 posts

Joined: May 2018


QUOTE(silverhawk @ Aug 26 2021, 07:28 PM)
There are some positions open in the company at the moment, so been doing some interviews. We have a warm-up question for the code whiteboarding session that goes like something like this

CODE

Write a function that takes an input number (e.g. 4) and prints:
1 2 3 4
1 2 3
1 2
1


and 90% of the candidates are failing this. All of the frontend candidates could not do this, even after some guidance. The opening is for a senior position with at least 5 years experience. While ability to answer the questions does not determine whether you get the offer or not, I find it quite odd that the warmup question is tripping people up.

Is anyone else facing this issue with their hiring? Should this level of problem solving ability not be expected of frontend devs?
*
This looks too simple. Sure it took me 10 seconds to look it has 2 dimensions so nested for loop is necessary. Another solution: 1.Create array of all items 2. Drop last item in each iteration.
TSsilverhawk
post Aug 27 2021, 12:59 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(malleus @ Aug 26 2021, 08:58 PM)
would have failed first year uni if not able to do this
*
Pretty much my thoughts, but these are people working in rather reputable companies, some are even leading teams! I'm honestly baffled

QUOTE(FlierMate @ Aug 26 2021, 09:35 PM)
It took me (as an old-timer) awhile to solve it. Initially I thought single loop was enough, but double loops are necessary. (See https://dotnetfiddle.net/6D78Dv, TQ for the exercise :=)

Maybe this question is too mind-boggling for frontend developers?  rclxub.gif    By all means, I am not qualified for web frontend tech stack either.
*
Don't feel bad, even we don't expect people to get it immediately. We just want to see how you think and come to a solution. You came to a solution, so all is good smile.gif

Technically, double loops are not necessary, its just the most straight forward way. Its possible to do it in a single loop. Want to give that a go? biggrin.gif

QUOTE(xhruso00 @ Aug 26 2021, 09:43 PM)
This looks too simple. Sure it took me 10 seconds to look it has 2 dimensions so nested for loop is necessary. Another solution: 1.Create array of all items 2. Drop last item in each iteration.
*
Its meant to be simple, suppose to warm you up and get you comfortable for the harder questions down the road.
flashang
post Aug 27 2021, 10:21 AM

Getting Started
**
Junior Member
175 posts

Joined: Aug 2021


if major task is web app, html + css + javascript should be more appropriate.

design a good question is not easy.

although most of the UI design (layout, animation, verification) could done without script,

at least basic level of coding skill is required.

from the structure of code been used,
you might see if the thought and logic is clear.

it seem can be done with single loop,
but you need some extra control,
which may make the loop - condition not so reading friendly,

as for double loop solution,
which may be more easier to read and understand for most of the people.

this question should not have a "standard answer".
but why they explain why they doing this way.


TSsilverhawk
post Aug 27 2021, 10:31 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(flashang @ Aug 27 2021, 10:21 AM)
if major task is web app, html + css + javascript should be more appropriate.

design a good question is not easy.

although most of the UI design (layout, animation, verification) could done without script,

at least basic level of coding skill is required.

from the structure of code been used,
you might see if the thought and logic is clear.

it seem can be done with single loop,
but you need some extra control,
which may make the loop - condition not so reading friendly,

as for double loop solution,
which may be more easier to read and understand for most of the people.

this question should not have a "standard answer".
but why they explain why they doing this way.
*
Yes, there is no standard answer, the problem is that they can't even produce the answer.

You want to do it via nested loop, single loop or even just pop off the array and console.log it at each iteration. I'm ok, as long as you can produce the result and explain the thought process.

The frontend candidates so far seem to think that by asking them questions like these, means we're expecting their workload to be algorithmically heavy and say things like "we don't do calculatiosn in the frontend".
malleus
post Aug 27 2021, 02:56 PM

Look at all my stars!!
*******
Senior Member
2,096 posts

Joined: Dec 2011
QUOTE(silverhawk @ Aug 27 2021, 10:31 AM)
Yes, there is no standard answer, the problem is that they can't even produce the answer.

You want to do it via nested loop, single loop or even just pop off the array and console.log it at each iteration. I'm ok, as long as you can produce the result and explain the thought process.

The frontend candidates so far seem to think that by asking them questions like these, means we're expecting their workload to be algorithmically heavy and say things like "we don't do calculatiosn in the frontend".
*
I'm expect something simple like this to be handled quite often on the frontend
TSsilverhawk
post Aug 27 2021, 04:17 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(malleus @ Aug 27 2021, 02:56 PM)
I'm expect something simple like this to be handled quite often on the frontend
*
Yeap, so I asked questions like "don't you do things like receive a result set of rows/columns and have to display them in a table or some sort". And the typical response I get is "we just pass the data into the component and the component renders it". doh.gif

To me, not passing question 1 pretty much disqualifies you as a candidate. However seeing the amount of people failing it, I'm entertaining the idea that my expectations might need adjustment, that's why I'm asking here.

Is it possible for a frontend dev to be any good if they can't solve that question? My thinking is no, but I'm open to be proven wrong.
SaberCortez
post Aug 27 2021, 04:19 PM

Enthusiast
*****
Senior Member
710 posts

Joined: Nov 2012



nested loop enuf no?
tekplyrX
post Aug 27 2021, 04:23 PM

Getting Started
**
Junior Member
140 posts

Joined: Feb 2009
lol, I have met "senior" developers that don't know that using callbacks causes the code to run asynchronously
SaberCortez
post Aug 27 2021, 04:23 PM

Enthusiast
*****
Senior Member
710 posts

Joined: Nov 2012



QUOTE(silverhawk @ Aug 27 2021, 05:17 PM)
Yeap, so I asked questions like "don't you do things like receive a result set of rows/columns and have to display them in a table or some sort". And the typical response I get is "we just pass the data into the component and the component renders it". doh.gif

To me, not passing question 1 pretty much disqualifies you as a candidate. However seeing the amount of people failing it, I'm entertaining the idea that my expectations might need adjustment, that's why I'm asking here.

Is it possible for a frontend dev to be any good if they can't solve that question? My thinking is no, but I'm open to be proven wrong.
*
Too much dependent on framework. that's why
shinichi88
post Aug 27 2021, 04:31 PM

Holy Crusader
*****
Senior Member
939 posts

Joined: Sep 2005
From: Selangor
QUOTE(FlierMate @ Aug 26 2021, 09:35 PM)
It took me (as an old-timer) awhile to solve it. Initially I thought single loop was enough, but double loops are necessary. (See https://dotnetfiddle.net/6D78Dv, TQ for the exercise :=)

Maybe this question is too mind-boggling for frontend developers?  rclxub.gif    By all means, I am not qualified for web frontend tech stack either.
*
Edit from this example.

CODE
Console.Write("Number? ");
 string numS=Console.ReadLine();
 int numI=Int16.Parse(numS);
 while(numI > 0)
 {
  for(int i=1; i<=numI; i++)
  {
   Console.Write(i.ToString() + ' ');
  }
  Console.WriteLine();
  numI--;
 }

Like this will do.

This post has been edited by shinichi88: Aug 27 2021, 04:32 PM
malleus
post Aug 27 2021, 05:10 PM

Look at all my stars!!
*******
Senior Member
2,096 posts

Joined: Dec 2011
QUOTE(silverhawk @ Aug 27 2021, 04:17 PM)
Yeap, so I asked questions like "don't you do things like receive a result set of rows/columns and have to display them in a table or some sort". And the typical response I get is "we just pass the data into the component and the component renders it". doh.gif

To me, not passing question 1 pretty much disqualifies you as a candidate. However seeing the amount of people failing it, I'm entertaining the idea that my expectations might need adjustment, that's why I'm asking here.

Is it possible for a frontend dev to be any good if they can't solve that question? My thinking is no, but I'm open to be proven wrong.
*
It's definitely a red flag. but I think I seen this primarily in ppl who worked a lot with wordpress only who calls into this category.

but there's another question that I have though. These candidates that you interviewed, what's their background? are they working as a web dev in a creative agency? as in, more of a design house or online marketing agency? the tech requirements for these places are rather different.

I've worked with one before where their web dev lead (he's actually more of a web designer than a web dev) does not know how to consume an API. and they had to fall back to making the API request, write the results to DB, then render the results to screen by querying it out of a DB.

sounds very similar to your example of 'we just pass the data into the component'
ragk
post Aug 27 2021, 05:37 PM

BooBoo~
*******
Senior Member
2,241 posts

Joined: Apr 2009


It's really depend on the individual I guess
That's ppl that only stay in their comfort zone, and that's ppl happy with new knowledge and challenge
Guess we have met both of the kind, we just need to spend time to look for the right fit
I have friend who working on the same office and same thing for 10 years using the same technology, can't say they are wrong, maybe just lack of option & oppournity in the future
TSsilverhawk
post Aug 27 2021, 07:16 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(tekplyrX @ Aug 27 2021, 04:23 PM)
lol, I have met "senior" developers that don't know that using callbacks causes the code to run asynchronously
*
In JS? I know what you mean, but its not necessarily true.

CODE

let total = 0;
items.forEach((item) => {
 total += item.count;
 });
return total;


This would run synchronously.

QUOTE(malleus @ Aug 27 2021, 05:10 PM)
It's definitely a red flag. but I think I seen this primarily in ppl who worked a lot with wordpress only who calls into this category.

but there's another question that I have though. These candidates that you interviewed, what's their background? are they working as a web dev in a creative agency? as in, more of a design house or online marketing agency? the tech requirements for these places are rather different.

I've worked with one before where their web dev lead (he's actually more of a web designer than a web dev) does not know how to consume an API. and they had to fall back to making the API request, write the results to DB, then render the results to screen by querying it out of a DB.

sounds very similar to your example of 'we just pass the data into the component'
*
They're not in creative agencies, they're in dev companies. I won't name the companies, but they are companies that you expect to have a higher technical requirement/background. Their job isn't wordpress, but a lot of it revolves using angular / reactJS / vueJs for internal/customer facing products.
tekplyrX
post Aug 27 2021, 08:01 PM

Getting Started
**
Junior Member
140 posts

Joined: Feb 2009
QUOTE(silverhawk @ Aug 27 2021, 07:16 PM)
In JS? I know what you mean, but its not necessarily true.

CODE

let total = 0;
items.forEach((item) => {
 total += item.count;
 });
return total;


This would run synchronously. ]
That is true because by default forEach expects a synchronous callback function. If you use an asynchronous function as the callback the code won't work, e.g.

CODE

let ratings = [5, 4, 5];
let sum = 0;

let sumFunction = async function (a, b)
{
 return a + b
}

ratings.forEach(async function(rating) {
 sum = await sumFunction(sum, rating)
})

console.log(sum)
// Naively expected output: 14
// Actual output: 0

kingkingyyk
post Aug 27 2021, 08:24 PM

10k Club
Group Icon
Elite
15,391 posts

Joined: Mar 2008
Obscenely short Python :
CODE
def solution(n: int):
   ans = [' '.join([str(y) for y in range(1,n+2-x)]) for x in range(1,n+1)]
   print('\n'.join(ans))

solution(4)


or maybe nicer.

CODE
def solution(n: int):
   full = [str(x) for x in list(range(1,n+2))]
   for i in range(1,n+1):
       print(' '.join(full[:-i]))

solution(4)


sweat.gif The truth is there are too many incompetent developers here.

This post has been edited by kingkingyyk: Aug 27 2021, 08:30 PM
FlierMate
post Aug 27 2021, 08:31 PM

On my way
****
Validating
515 posts

Joined: Nov 2020
QUOTE(silverhawk @ Aug 27 2021, 12:59 AM)
Don't feel bad, even we don't expect people to get it immediately. We just want to see how you think and come to a solution. You came to a solution, so all is good smile.gif

Technically, double loops are not necessary, its just the most straight forward way. Its possible to do it in a single loop. Want to give that a go? biggrin.gif
*
This is it: (https://dotnetfiddle.net/17WiGT)

CODE

using System;
   
public class Program
{
public static void Main()
{
 Console.Write("Number? ");
  string numS=Console.ReadLine();
  int numI=Int16.Parse(numS);
 for(int i=1; i<=numI*numI; i++)
 {
  Console.Write((i % (numI+1)).ToString() + ' ');
  if ((i % numI)==0)
  {
   i+=i / numI;
   Console.WriteLine();
  }
 }
}
}


Single loop, but MOD and DIV are necessary. Thank you for giving me another chance. icon_rolleyes.gif
Lord Tiki Mick
post Aug 27 2021, 09:34 PM

Regular
******
Senior Member
1,012 posts

Joined: Jul 2012
This is my solution using Java 11. cool2.gif

CODE

public class Answer {
   public static void main(String[] args) {
       var n = Integer.parseInt(args[0]);
       while (n > 0) {
           var sj = new java.util.StringJoiner(" ");
           for (var i = 1; i <= n; i++) {
               sj.add(String.valueOf(i));
           }

           System.out.println(sj);
           n--;
       }
   }
}


Here I use the StringJoiner class, so that the output will not have a trailing space.
I tend use String.valueOf(i) instead of "" + i because I don't know whether the compiler will optimize the later. hmm.gif

Notice that, Java now have var keywordtype. biggrin.gif
mykk
post Aug 27 2021, 11:14 PM

Getting Started
**
Junior Member
91 posts

Joined: Jan 2003
using c
CODE

#include <stdio.h>

int main(void)
{
int n = 0;
int i = 0;

printf("Enter number : ");
scanf("%d", &n);

for(i = 1; i <= n; i++)
{
 printf("%d ", i);
 if(i == n)
 {
  printf("\n");
  n--;
  i = 0;
 }
 
}

return 0;
}


TSsilverhawk
post Aug 27 2021, 11:45 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(tekplyrX @ Aug 27 2021, 08:01 PM)
That is true because by default forEach expects a synchronous callback function. If you use an asynchronous function as the callback the code won't work, e.g.

*
Yea, but since you define it as async already, then its rather obvious. Could do something a bit more tricky like this:

CODE

let i;
for (i = 0; i < 3; i++) {
 const log = () => {
   console.log(i);
 }
 setTimeout(log, 100);
}


If you really know your JS, the answer might be obvious to you. However even experienced devs trip up on this, though most of them will get the right answer once they take a closer look.

QUOTE(FlierMate @ Aug 27 2021, 08:31 PM)
This is it: (https://dotnetfiddle.net/17WiGT)

CODE

using System;
   
public class Program
{
public static void Main()
{
 Console.Write("Number? ");
  string numS=Console.ReadLine();
  int numI=Int16.Parse(numS);
 for(int i=1; i<=numI*numI; i++)
 {
  Console.Write((i % (numI+1)).ToString() + ' ');
  if ((i % numI)==0)
  {
   i+=i / numI;
   Console.WriteLine();
  }
 }
}
}


Single loop, but MOD and DIV are necessary. Thank you for giving me another chance.  icon_rolleyes.gif
*
Good job thumbup.gif It can be simpler though.
praetorion
post Aug 27 2021, 11:51 PM

Getting Started
**
Junior Member
284 posts

Joined: Jan 2003
From: MAS
the point is to see the candidate logical thinking, how to react under pressure, problem solving skill, or maybe if the candidate truly experience, how to taichi out of the question.

no?
techm
post Aug 28 2021, 12:08 AM

Getting Started
**
Junior Member
113 posts

Joined: Nov 2007
This should be a pretty simple exercise to test candidate's ability to analyse the problem and break down problem into simpler steps. I'd drop them if they can't even solve it to be honest. No guidance necessary.

For those who pass, you can try asking them to also provide a solution that doesn't use loops. That'll be fun.

This post has been edited by techm: Aug 28 2021, 12:10 AM
TSsilverhawk
post Aug 28 2021, 12:44 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(praetorion @ Aug 27 2021, 11:51 PM)
the point is to see the candidate logical thinking, how to react under pressure, problem solving skill, or maybe if the candidate truly experience, how to taichi out of the question.

no?
*
Yes, but this particular question I never expected I needed to do any guidance. Its meant to warm you up for the upcoming questions. I'll still be fair and provide guidance to see where they end up.

QUOTE(techm @ Aug 28 2021, 12:08 AM)
This should be a pretty simple exercise to test candidate's ability to analyse the problem and break down problem into simpler steps. I'd drop them if they can't even solve it to be honest. No guidance necessary.

For those who pass, you can try asking them to also provide a solution that doesn't use loops. That'll be fun.
*
Those that pass get other questions, we expect most to pass... but lately most fail. Its perplexing.

Though I think its good to see that most of you guys here are solving it without any issue. Most of us are also still of the opinion that this is too basic to not know.
FlierMate
post Aug 28 2021, 01:23 AM

On my way
****
Validating
515 posts

Joined: Nov 2020
QUOTE(silverhawk @ Aug 27 2021, 11:45 PM)

Good job thumbup.gif It can be simpler though.
*
I think @mykk has a good answer. @kingkingykk too, but I don't understand much about Python.

@shinichi88's solution is the same as @Lord Tiki Mick, both are already good enough.

I have another alternative solution (which accepts number 1..9 only):

CODE
 Console.Write("Number? ");
  string numS=Console.ReadLine();
  int numI=Int16.Parse(numS);  
 string S="1 2 3 4 5 6 7 8 9 ";
 for (int i=0; i<=numI; i++)
 {  
  Console.WriteLine(S.Substring(0, (numI - i) * 2));  
 }


I don't think it can be done without any loop, maybe someone can try?
techm
post Aug 28 2021, 08:02 AM

Getting Started
**
Junior Member
113 posts

Joined: Nov 2007
It is totally possible to do it without loops.

It has limitations/drawbacks though, which any intermediate/experienced programmer should also be able to tell.

» Click to show Spoiler - click again to hide... «



This post has been edited by techm: Aug 28 2021, 08:57 AM
FlierMate
post Aug 28 2021, 09:07 AM

On my way
****
Validating
515 posts

Joined: Nov 2020
QUOTE(techm @ Aug 28 2021, 08:02 AM)
It is totally possible to do it without loops.

It has limitations/drawbacks though, which any intermediate/experienced programmer should also be able to tell.

» Click to show Spoiler - click again to hide... «

*
Hey! This is really cool!

I am able to translate your code to C#, but in a poorer way:

CODE

using System;
   
public class Program
{
public static void f(int x, int y)
{
 if (x<y)
 {
  Console.Write(x + " ");
  f(x+1,y);
 }
 if (x==y)
 {
  Console.WriteLine(y);
  f(1,y-1);  
 }
}

public static void Main()
{
 Console.Write("Number? ");
  string numS=Console.ReadLine();
  int numI=Int16.Parse(numS);
 
 f(1,numI);
}
}


Thumbs up for your code! thumbsup.gif
FlierMate
post Aug 28 2021, 10:40 AM

On my way
****
Validating
515 posts

Joined: Nov 2020
I have created another simple version (accepting number 1~9 only) in ASM (for 32-bit Linux):

jdoodle.com/ia/gp8 (Type the digit 1..9 in StdIn input column first)

I am a rookie.... rolleyes.gif

» Click to show Spoiler - click again to hide... «

TSsilverhawk
post Aug 28 2021, 11:45 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(FlierMate @ Aug 28 2021, 10:40 AM)
I have created another simple version (accepting number 1~9 only) in ASM (for 32-bit Linux):

jdoodle.com/ia/gp8  (Type the digit 1..9 in StdIn input column first)

I am a rookie....  rolleyes.gif

» Click to show Spoiler - click again to hide... «

*
thumbup.gif

You're really enjoying this aren't you? laugh.gif Keep up that attitude, its amazing smile.gif

This post has been edited by silverhawk: Aug 28 2021, 11:46 AM
nyem
post Aug 28 2021, 02:09 PM

Enthusiast
*****
Senior Member
746 posts

Joined: Jan 2007


Been playing with javascript arrays, and with some handy js libraries at hand this would be my quick solution using d3.js

CODE

function ly(n=4)  {
 if (!n) console.warn('n', n);
 let k = d3.range(1, n+1);
 while (k.length)  {
   console.log(k.join('\t'));
   k = k.slice(0, -1);
 }
}

ly();
ly(14);
ly(0);
ly(null);



But then when the question popups out of nowhere without my handy libraries around I'll definitely struggle. Might panic and spurt out nonsense before I can come up with this pure js function

CODE

function ly(n=4)  {
 if (!n) console.warn('n', n);
 let k = Array(n).fill().map((d,i)=>i+1);
 while (k.length)  {
   console.log(k.join('\t'));
   k = k.slice(0, -1);
 }
}




techm
post Aug 28 2021, 04:48 PM

Getting Started
**
Junior Member
113 posts

Joined: Nov 2007
Wow..x86 assembly...lol. The last time I used them was like...almost 28 years ago. Shy. I probably just revealed my age. blink.gif
Now I'm too old my brain too lazy to think in assembler already.


QUOTE(FlierMate @ Aug 28 2021, 10:40 AM)
I have created another simple version (accepting number 1~9 only) in ASM (for 32-bit Linux):

jdoodle.com/ia/gp8  (Type the digit 1..9 in StdIn input column first)

I am a rookie....  rolleyes.gif

» Click to show Spoiler - click again to hide... «

*
FlierMate
post Aug 28 2021, 05:05 PM

On my way
****
Validating
515 posts

Joined: Nov 2020
QUOTE(silverhawk @ Aug 28 2021, 11:45 AM)
thumbup.gif

You're really enjoying this aren't you? laugh.gif Keep up that attitude, its amazing smile.gif
*
Too bored at home, plus I need to sharpen my mind, so I am glad can practice using your question. biggrin.gif

QUOTE(nyem @ Aug 28 2021, 02:09 PM)
Been playing with javascript arrays, and with some handy js libraries at hand this would be my quick solution using d3.js
» Click to show Spoiler - click again to hide... «


But then when the question popups out of nowhere without my handy libraries around I'll definitely struggle. Might panic and spurt out nonsense before I can come up with this pure js function

CODE

function ly(n=4)  {
 if (!n) console.warn('n', n);
 let k = Array(n).fill().map((d,i)=>i+1);
 while (k.length)  {
   console.log(k.join('\t'));
   k = k.slice(0, -1);
 }
}


*
Nice, learn something new in Javascript from you.

ly(8) shows:
user posted image


QUOTE(techm @ Aug 28 2021, 04:48 PM)
Wow..x86 assembly...lol.  The last time I used them was like...almost 28 years ago. Shy. I probably just revealed my age.  blink.gif
Now I'm too old my brain too lazy to think in assembler already.
*
We are the same generation, no worries. laugh.gif
Looks like a lot of old-timers were once active in Assembly programming.
You already have a nice solution for this question.
techm
post Aug 28 2021, 06:15 PM

Getting Started
**
Junior Member
113 posts

Joined: Nov 2007
QUOTE(FlierMate @ Aug 28 2021, 05:05 PM)
Looks like a lot of old-timers were once active in Assembly programming.
Haha. That's because CPUs weren't fast enough back then, memory not enough, and lack of fast compiled languages other than C/Pascal. So asm was simply out of necessity.
Nowadays Go,Java,C#,Javascript all run damn fast already. Better save brain cycles for learning the 1001 frameworks and tools now rclxub.gif

TSsilverhawk
post Aug 28 2021, 07:17 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(nyem @ Aug 28 2021, 02:09 PM)
Been playing with javascript arrays, and with some handy js libraries at hand this would be my quick solution using d3.js

CODE

function ly(n=4)  {
 if (!n) console.warn('n', n);
 let k = d3.range(1, n+1);
 while (k.length)  {
   console.log(k.join('\t'));
   k = k.slice(0, -1);
 }
}

ly();
ly(14);
ly(0);
ly(null);



But then when the question popups out of nowhere without my handy libraries around I'll definitely struggle. Might panic and spurt out nonsense before I can come up with this pure js function

CODE

function ly(n=4)  {
 if (!n) console.warn('n', n);
 let k = Array(n).fill().map((d,i)=>i+1);
 while (k.length)  {
   console.log(k.join('\t'));
   k = k.slice(0, -1);
 }
}


*
We don't need it to be JS, pseudocode is fine. However you score more points if you write the code properly in the language of your choice.

That said, be careful of using libraries/functions if you ever come across questions like these in your interview. Typically we will ask you to implement the library function you just used.

Out of curiosity, why did you think of using arrays? Those are generally more complicated. Was a nested for loop part of your consideration, if not why? If you had to do this without using loops, how would you approach it?

QUOTE(FlierMate @ Aug 28 2021, 05:05 PM)
Too bored at home, plus I need to sharpen my mind, so I am glad can practice using your question.  biggrin.gif
*
Nah, give you something fun: https://leetcode.com/

Grammar Police
post Aug 28 2021, 08:37 PM

Casual
***
Junior Member
332 posts

Joined: Mar 2016
QUOTE(silverhawk @ Aug 26 2021, 07:28 PM)
There are some positions open in the company at the moment, so been doing some interviews. We have a warm-up question for the code whiteboarding session that goes like something like this

CODE

Write a function that takes an input number (e.g. 4) and prints:
1 2 3 4
1 2 3
1 2
1


and 90% of the candidates are failing this. All of the frontend candidates could not do this, even after some guidance. The opening is for a senior position with at least 5 years experience. While ability to answer the questions does not determine whether you get the offer or not, I find it quite odd that the warmup question is tripping people up.

Is anyone else facing this issue with their hiring? Should this level of problem solving ability not be expected of frontend devs?
*
CODE


<script>



let n = prompt("input a number");

if (!isNaN(n)) {

for (let i=0; i < n; i ++ ) {
    let arr = []
    for (let o=1; o < parseInt(n)+1-i; o ++ ) {
     arr.push(o)
    }
       console.log(arr, n, i)
}
}

i know nesting loop is noob way of doing it but i want to do it fast and too lazy to google on how to populate an array and then reduce it later... i think its array.Fill() or something


</script>



Grammar Police
post Aug 28 2021, 08:49 PM

Casual
***
Junior Member
332 posts

Joined: Mar 2016
QUOTE(silverhawk @ Aug 27 2021, 12:59 AM)
Pretty much my thoughts, but these are people working in rather reputable companies, some are even leading teams! I'm honestly baffled
Don't feel bad, even we don't expect people to get it immediately. We just want to see how you think and come to a solution. You came to a solution, so all is good smile.gif

Technically, double loops are not necessary, its just the most straight forward way. Its possible to do it in a single loop. Want to give that a go? biggrin.gif
Its meant to be simple, suppose to warm you up and get you comfortable for the harder questions down the road.
*
oh wow

CODE


<script>
var n = 4

for (let i=0; i < n; i ++ ) {

   var arr = Array.from(Array(n-i+1).keys())
   
   console.log(arr, n,i)
}
</script>




» Click to show Spoiler - click again to hide... «

flashang
post Aug 28 2021, 09:58 PM

Getting Started
**
Junior Member
175 posts

Joined: Aug 2021


Just wonder why didn't see double for loop :
CODE

void f2( int n ) {
for( int line=1; line <= n; ++line ) {
 for( int col=1; col <= (n-line+1); ++col ) {
  printf( "%d ", col );
 } // for col
 printf( "\n" );
} // for line
} // f2




After combined @shinichi88 and @mykk method, single loop :
CODE

void f1( int n ) {
int j = 0;
while( n > 0 ) {
 ++j;
 printf( "%d ", j );
 if( j== n ) {
  --n;
  j = 0;
  printf( "\n" );
 } // if
} // while
} // f1


smile.gif


flashang
post Aug 28 2021, 10:45 PM

Getting Started
**
Junior Member
175 posts

Joined: Aug 2021


QUOTE(flashang @ Aug 28 2021, 09:58 PM)
Just wonder why didn't see double for loop :
CODE

void f2( int n ) {
for( int line=1; line <= n; ++line ) {
 for( int col=1; col <= (n-line+1); ++col ) {
  printf( "%d ", col );
 } // for col
 printf( "\n" );
} // for line
} // f2

After combined @shinichi88 and @mykk method, single loop :
CODE

void f1( int n ) {
int j = 0;
while( n > 0 ) {
 ++j;
 printf( "%d ", j );
 if( j== n ) {
  --n;
  j = 0;
  printf( "\n" );
 } // if
} // while
} // f1


smile.gif
*
To simplify the calculation for 2nd loop :
CODE

void f3( int n ) {
   for( int line=n; line > 0; --line ) {
       for( int col=1; col <= line; ++col ) {
           printf( "%d ", col );
       } // for col
       printf( "\n" );
   } // for line
} // f3


smile.gif


TSsilverhawk
post Aug 28 2021, 11:45 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(Grammar Police @ Aug 28 2021, 08:49 PM)
I googled user posted image

didnt have all the array methods at heart
*
No shame in it, its a learning experience smile.gif

Curious though, why do you think you have to use arrays?

flashang
post Aug 29 2021, 12:26 AM

Getting Started
**
Junior Member
175 posts

Joined: Aug 2021


for Javascript, single loop :

CODE

function f1( n ) {
   let j = 0;
   let str = "";
   while( n > 0 ) {
       ++j;
       str += j + " ";
       if( j== n ) {
           --n;
           j = 0;
           console.log( str );
           document.write( str + "<br/>");
           str = "";
       } // if
   } // while
} // f1


double for :
CODE

function f3( n ) {
   let str = "";
   for( let line=n; line > 0; --line ) {
       for( let col=1; col <= line; ++col ) {
           str += col + " ";
       } // for col
       console.log( str );
       document.write( str + "<br/>");
       str = "";
   } // for line
} // f3


smile.gif


Grammar Police
post Aug 29 2021, 01:07 AM

Casual
***
Junior Member
332 posts

Joined: Mar 2016
QUOTE(silverhawk @ Aug 28 2021, 11:45 PM)
No shame in it, its a learning experience smile.gif

Curious though, why do you think you have to use arrays?
*
when i saw 1 2 3 4

i thought an array with [1,2,3,4]

must it be a string?
TSsilverhawk
post Aug 29 2021, 01:18 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(Grammar Police @ Aug 29 2021, 01:07 AM)
when i saw 1 2 3 4

i thought an array with [1,2,3,4]

must it be a string?
*
not necessary, but strings are more straightforward to deal with. Its just that the frontend candidates tend to jump to using an array, while backend/full stack devs will tend to use a string/output approach.


nyem
post Aug 29 2021, 01:19 AM

Enthusiast
*****
Senior Member
746 posts

Joined: Jan 2007


QUOTE(silverhawk @ Aug 28 2021, 07:17 PM)
Out of curiosity, why did you think of using arrays? Those are generally more complicated. Was a nested for loop part of your consideration, if not why? If you had to do this without using loops, how would you approach it?
There are bunch of js built-in functions available for working with arrays, and I'm still learning tongue.gif

Here's another version using seldom-used 3rd parameter of forEach

CODE


function ly(n=4)  {

 if (!n) console.warn('n', n);

 Array(n)
   .fill().map((d,i)=>i+1)
   .forEach((d,i,j)=>console.log( j.slice(0, n-i).join('\t') ))

}

ly(10);



Grammar Police
post Aug 29 2021, 01:43 AM

Casual
***
Junior Member
332 posts

Joined: Mar 2016
QUOTE(silverhawk @ Aug 29 2021, 01:18 AM)
not necessary, but strings are more straightforward to deal with. Its just that the frontend candidates tend to jump to using an array, while backend/full stack devs will tend to use a string/output approach.
*
got more challenge questions like this ? sunday is boring
tryifelsecatch
post Aug 29 2021, 02:16 AM

Casual
***
Junior Member
474 posts

Joined: Mar 2009
rate mine

CODE

using System;
   
public class Program
{
public static void Main()
{
 Console.Write("Your Input : ");
   int arg = Int16.Parse(Console.ReadLine());    
 foo(arg);  
}

private static void foo (int arg) {      
 if (arg == 1) {    
  Console.WriteLine(1);
 }
 else {
  for (int i = 1; i <= arg; i++)
  {    
   Console.Write(i + " ");  
  }
 
  if (arg > 1) {
   arg = arg - 1;    
   Console.WriteLine();
   foo(arg);    
  }  
 }

}
}

flashang
post Aug 29 2021, 10:36 AM

Getting Started
**
Junior Member
175 posts

Joined: Aug 2021


QUOTE(tryifelsecatch @ Aug 29 2021, 02:16 AM)
rate mine

CODE

using System;
   
public class Program
{
public static void Main()
{
 Console.Write("Your Input : ");
   int arg = Int16.Parse(Console.ReadLine());    
 foo(arg);  
}

private static void foo (int arg) {      
 if (arg == 1) {    
  Console.WriteLine(1);
 }
 else {
  for (int i = 1; i <= arg; i++)
  {    
   Console.Write(i + " ");  
  }
 
  if (arg > 1) {
   arg = arg - 1;    
   Console.WriteLine();
   foo(arg);    
  }  
 }

}
}

*
modified from your code. the loop can process "1"
CODE

void tryifelsecatch_foo2 (int arg) {
   for (int i = 1; i <= arg; i++) {
       // Console.Write(i + " ");
       printf( "%d ", i );
   } // for

   if (arg > 1) {
       arg = arg - 1;
       // Console.WriteLine();
       printf( "\n" );
       tryifelsecatch_foo2(arg);
   } // if
}


smile.gif


TSsilverhawk
post Aug 29 2021, 11:57 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(Grammar Police @ Aug 29 2021, 01:43 AM)
got more challenge questions like this ? sunday is boring
*
Try this:

CODE
Write a function to transpose a multi-dimensional array from

1 2 3
4 5 6
7 8 9
to
1 4 7
2 5 8
3 6 9


QUOTE(tryifelsecatch @ Aug 29 2021, 02:16 AM)
rate mine

*
Not bad. Generally having an additional specific check like that is a bad idea though. If the for loop can handle it, it should.
epud2 P
post Aug 29 2021, 01:47 PM

New Member
*
Probation
4 posts

Joined: Aug 2021
CODE
Write a function to transpose a multi-dimensional array from

1 2 3
4 5 6
7 8 9
to
1 4 7
2 5 8
3 6 9


CODE

var a = [[1,2,3],[4,5,6],[7,8,9]]
var b = [[1,2,3],[4,5,6],[7,8,9]]

for (let x = 0; x<a.length; x++){
   for (let y = 0; y<a.length; y++){
       b[x][y] = a[y][x]
   }
}
console.log(b)

Grammar Police
post Aug 29 2021, 02:20 PM

Casual
***
Junior Member
332 posts

Joined: Mar 2016
QUOTE(silverhawk @ Aug 29 2021, 11:57 AM)
Try this:

CODE
Write a function to transpose a multi-dimensional array from

1 2 3
4 5 6
7 8 9
to
1 4 7
2 5 8
3 6 9

Not bad. Generally having an additional specific check like that is a bad idea though. If the for loop can handle it, it should.
*
CODE


<script>

let arr = [
[1 ,2 ,3],
   [4, 5, 6],
   [7, 8 , 9]
]

let newArr = [];

for (let i =0;i<arr.length;i++) {
let childArr = []
for (let o =0;o<arr[i].length;o++) {
    console.log(arr[i][o], i)
    childArr.push(arr[o][i]);

}
newArr.push(childArr)
}
console.log(newArr)

</script>




yawn.gif yawn.gif yawn.gif
tryifelsecatch
post Aug 29 2021, 02:58 PM

Casual
***
Junior Member
474 posts

Joined: Mar 2009
QUOTE(silverhawk @ Aug 29 2021, 11:57 AM)

Not bad. Generally having an additional specific check like that is a bad idea though. If the for loop can handle it, it should.
*
care to elaborate why is it bad?
i thought the complexity should be the same at O(1) for If and O(n) n=1 for For loop.
techm
post Aug 29 2021, 04:08 PM

Getting Started
**
Junior Member
113 posts

Joined: Nov 2007
QUOTE(epud2 @ Aug 29 2021, 01:47 PM)
CODE

var a = [[1,2,3],[4,5,6],[7,8,9]]
var b = [[1,2,3],[4,5,6],[7,8,9]]

for (let x = 0; x<a.length; x++){
   for (let y = 0; y<a.length; y++){
       b[x][y] = a[y][x]
   }
}
console.log(b)
I like this. Clean and straightforward. But it fails on rectangular matrices though.

Out of curiosity, i googled and found a 1-liner pure JS code on stackoverflow that does the transposition. Mind blown.



nyem
post Aug 29 2021, 04:33 PM

Enthusiast
*****
Senior Member
746 posts

Joined: Jan 2007


CODE

`
1 2 3
4 5 6
7 8 9
`.split(/\n/)
 .filter(d=>d)
 .map(d=>d.trim().split(/\s+/))
 .forEach((_,i,j)=>console.log(
   Array(j.length)
     .fill()
     .map((_,k)=>j[k][i])
     .join('\t')
   )
 );


epud2 P
post Aug 29 2021, 05:00 PM

New Member
*
Probation
4 posts

Joined: Aug 2021
QUOTE(techm @ Aug 29 2021, 04:08 PM)
I like this. Clean and straightforward. But it fails on rectangular matrices though.

Out of curiosity, i googled and found a 1-liner pure JS code on stackoverflow that does the transposition. Mind blown.
*
Im aware of it. I thought transpose won't work on matrix other than nxn. I was wrong


QUOTE(nyem @ Aug 29 2021, 04:33 PM)
CODE

`
1 2 3
4 5 6
7 8 9
`.split(/\n/)
 .filter(d=>d)
 .map(d=>d.trim().split(/\s+/))
 .forEach((_,i,j)=>console.log(
   Array(j.length)
     .fill()
     .map((_,k)=>j[k][i])
     .join('\t')
   )
 );


*
I believe this code won't work on nxm matrix

CODE
input
1  2 3  4
5  6 7  8
9 10 11 12

output
1 5 9
2 6 10
3 7 11

nyem
post Aug 29 2021, 05:45 PM

Enthusiast
*****
Senior Member
746 posts

Joined: Jan 2007


See if this will work with nxm matrix

CODE

function str2matrix(str){
 return str.split(/\n/)
         .filter(d=>d)
         .map(d=>d.trim().split(/\s+/).filter(d=>d))
}

function transpose(m)  {
 return Array(m[0].length).fill().map((_,i)=>{
   return Array(m.length-1).fill().map((_,j)=>{
     return m[j][i];
   })
 })
}


transpose(
 str2matrix(`
   1 2 3 4 5
   6 7 8 9 10
 `)
)

1 6
2 7
3 8
4 9
5 10


transpose(
 str2matrix(`
   1 2 3
   4 5 6
   7 8 9
   10 11 12
   13 14 15
 `)
)

1 4 7 10 13
2 5 8 11 14
3 6 9 12 15


epud2 P
post Aug 29 2021, 06:00 PM

New Member
*
Probation
4 posts

Joined: Aug 2021
CODE
function logic(a,b){
   for (let y = 0; y<a[0].length; y++){
       let tmp = []
       for (let x = 0; x<a.length; x++){
           tmp.push(a[x][y])
      }
      b.push(tmp)
   }
   return b
}

var a = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
var b = []
logic(a,b)

var a = [[1,5,9],[2,6,10],[3,7,11],[4,8,12]]
var b = []
logic(a,b) //Should return back [[1,2,3,4],[5,6,7,8],[9,10,11,12]]


should work for n X n or n X m matrix
TSsilverhawk
post Aug 29 2021, 06:52 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(tryifelsecatch @ Aug 29 2021, 02:58 PM)
care to elaborate why is it bad?
i thought the complexity should be the same at O(1) for If and O(n) n=1 for For loop.
*
because you're creating unnecessary exceptions to your logic, its not like you're getting any real performance benefit for doing so either. Small exceptional optimisations like these tend to create unexpected bugs if requirements change.

malleus
post Aug 29 2021, 11:36 PM

Look at all my stars!!
*******
Senior Member
2,096 posts

Joined: Dec 2011
QUOTE(silverhawk @ Aug 29 2021, 06:52 PM)
because you're creating unnecessary exceptions to your logic, its not like you're getting any real performance benefit for doing so either. Small exceptional optimisations like these tend to create unexpected bugs if requirements change.
*
The other thing to watch out for is maintainability. ie: a few months down the road, can one still remember what they were doing, or a year later when somebody else looks at it.

The one question that we always have to ask ourself is, what is the value of the work that we do, considering how much we charge for it? spending too much time on small optimisations with too little returns is not something beneficial to clients, and may result in them questioning what exactly it is that they're paying for.

This is also one of the things that we take into consideration when determine when a developer is ready to move to a senior position or not, on if they're able to identify situations when they're supposed to optimise, and situations when they're not supposed to.
bumpo
post Aug 30 2021, 06:02 PM

On my way
****
Junior Member
632 posts

Joined: Mar 2013


my goodest answer:

print("1234\n123\n12\n1")

what if its 10 instead of 4 you ask? answer is "not part of original specs, please raise CR" rclxms.gif
habis terus kena shown the door laugh.gif

QUOTE(silverhawk @ Aug 27 2021, 04:17 PM)
Yeap, so I asked questions like "don't you do things like receive a result set of rows/columns and have to display them in a table or some sort". And the typical response I get is "we just pass the data into the component and the component renders it". doh.gif

To me, not passing question 1 pretty much disqualifies you as a candidate. However seeing the amount of people failing it, I'm entertaining the idea that my expectations might need adjustment, that's why I'm asking here.

Is it possible for a frontend dev to be any good if they can't solve that question? My thinking is no, but I'm open to be proven wrong.
*
this is a rather growing problem. next next generation is learning only how to use the framework but none of the basic underlying stuff that the framework is suppose to help simplify.
what makes it scary is that most of them dont even have the awareness of what they are investing their time in mastering shocking.gif
flashang
post Aug 30 2021, 07:42 PM

Getting Started
**
Junior Member
175 posts

Joined: Aug 2021


QUOTE(bumpo @ Aug 30 2021, 06:02 PM)
my goodest answer:

print("1234\n123\n12\n1")

what if its 10 instead of 4 you ask? answer is "not part of original specs, please raise CR"  rclxms.gif
habis terus kena shown the door  laugh.gif
this is a rather growing problem. next next generation is learning only how to use the framework but none of the basic underlying stuff that the framework is suppose to help simplify.
what makes it scary is that most of them dont even have the awareness of what they are investing their time in mastering shocking.gif
*
you may missed the original request / specs :
QUOTE
Write a function that takes an input number (e.g. 4) and prints:
smile.gif


TSsilverhawk
post Aug 31 2021, 01:23 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(bumpo @ Aug 30 2021, 06:02 PM)
my goodest answer:

print("1234\n123\n12\n1")

what if its 10 instead of 4 you ask? answer is "not part of original specs, please raise CR"  rclxms.gif
habis terus kena shown the door  laugh.gif

I would write you a referral for a comedy club on your way out laugh.gif

QUOTE
this is a rather growing problem. next next generation is learning only how to use the framework but none of the basic underlying stuff that the framework is suppose to help simplify.
what makes it scary is that most of them dont even have the awareness of what they are investing their time in mastering shocking.gif
*
You can't master anything without understanding some of the basic foundation/fundamentals. If that is all they got, they are at risk of being automated away by AI
pujan
post Sep 4 2021, 12:59 PM

Getting Started
**
Junior Member
83 posts

Joined: Apr 2009
I love a good brain teaser. Took me some thinking to answer that. My version (in JavaScript):

CODE

let weird = (num) => {
 let lines = num;
 let results = [];
 while (lines > 0) {
     let text = '';
     for (let i = 1; i <= lines; i++) {
        text = text + i + ' ';
     }
     results.push(text);
     lines--;
 }
 results.forEach(r => console.log(r.trim()));
}


OT: I agree with TS because in my opinion, this is not really something for front-end developers to figure out themselves. At most, there will be libraries that can take care of these sort of things before they even have to write their own. Or at the very least, it's not meant for entry level positions.
FlierMate
post Sep 4 2021, 05:33 PM

On my way
****
Validating
515 posts

Joined: Nov 2020
QUOTE(pujan @ Sep 4 2021, 12:59 PM)
I love a good brain teaser. Took me some thinking to answer that. My version (in JavaScript):

CODE

let weird = (num) => {
 let lines = num;
 let results = [];
 while (lines > 0) {
     let text = '';
     for (let i = 1; i <= lines; i++) {
        text = text + i + ' ';
     }
     results.push(text);
     lines--;
 }
 results.forEach(r => console.log(r.trim()));
}


OT: I agree with TS because in my opinion, this is not really something for front-end developers to figure out themselves. At most, there will be libraries that can take care of these sort of things before they even have to write their own. Or at the very least, it's not meant for entry level positions.
*
It works nicely:
user posted image

I called "weird(4)" and above was the console output.


bumpo
post Sep 6 2021, 10:16 AM

On my way
****
Junior Member
632 posts

Joined: Mar 2013


QUOTE(pujan @ Sep 4 2021, 12:59 PM)
I love a good brain teaser. Took me some thinking to answer that. My version (in JavaScript):

CODE

let weird = (num) => {
 let lines = num;
 let results = [];
 while (lines > 0) {
     let text = '';
     for (let i = 1; i <= lines; i++) {
        text = text + i + ' ';
     }
     results.push(text);
     lines--;
 }
 results.forEach(r => console.log(r.trim()));
}


OT: I agree with TS because in my opinion, this is not really something for front-end developers to figure out themselves. At most, there will be libraries that can take care of these sort of things before they even have to write their own. Or at the very least, it's not meant for entry level positions.
*
I kind of disagree. This exercise shows the person though process on how to approach a problem. If you cannot figure it out in step by step manner then you gonna have a tough time ahead. There is only so many blind copy pasta you can do before everything breaks
TSsilverhawk
post Sep 6 2021, 05:26 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(pujan @ Sep 4 2021, 12:59 PM)
I love a good brain teaser. Took me some thinking to answer that. My version (in JavaScript):

CODE

let weird = (num) => {
 let lines = num;
 let results = [];
 while (lines > 0) {
     let text = '';
     for (let i = 1; i <= lines; i++) {
        text = text + i + ' ';
     }
     results.push(text);
     lines--;
 }
 results.forEach(r => console.log(r.trim()));
}


OT: I agree with TS because in my opinion, this is not really something for front-end developers to figure out themselves. At most, there will be libraries that can take care of these sort of things before they even have to write their own. Or at the very least, it's not meant for entry level positions.
*
If you agree with me, that means you agree that frontend devs need to know this at least.

If all you can do as a dev is use libraries... what good are you? I might as well use low-code solutions at that point cause all the frontend dev is doing is calling functions and not problem solving. Personally I'm still of the opinion that even entry-level devs should be able to do this, its too damn basic. I'm open to be convinced otherwise, but I've not heard a single compelling argument so far
pujan
post Sep 7 2021, 10:44 AM

Getting Started
**
Junior Member
83 posts

Joined: Apr 2009
Hmm, thinking from an employer point of view or as someone who is in charge of the project, being able to do this is definitely needed by all the developers for the longevity and scalability of the product. Not sure what level this should be, perhaps entry, but then like you said, it will decrease the amount of selection of your candidates in the real world.

Wise words from who I call my mentor:
QUOTE
"In coding, it's normal to copy paste here and there from external sources, but you need to fully understand what you're copying and pasting."


This post has been edited by pujan: Sep 7 2021, 10:58 AM
flashang
post Sep 7 2021, 12:27 PM

Getting Started
**
Junior Member
175 posts

Joined: Aug 2021


QUOTE(pujan @ Sep 7 2021, 10:44 AM)
Hmm, thinking from an employer point of view or as someone who is in charge of the project, being able to do this is definitely needed by all the developers for the longevity and scalability of the product. Not sure what level this should be, perhaps entry, but then like you said, it will decrease the amount of selection of your candidates in the real world.

Wise words from who I call my mentor:
*
Beside show problem asking for solution,
You may show the code and ask what is the output ?

Should be html + css + js question, for web frontend.

Some example just for reference :
https: // fullgrade.com/tutor-problem/what-is-the-output-of-the-code/

smile.gif


TSsilverhawk
post Sep 7 2021, 04:21 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(pujan @ Sep 7 2021, 10:44 AM)
Hmm, thinking from an employer point of view or as someone who is in charge of the project, being able to do this is definitely needed by all the developers for the longevity and scalability of the product. Not sure what level this should be, perhaps entry, but then like you said, it will decrease the amount of selection of your candidates in the real world.

Intern level, maybe. Entry... eh, I still think you would need to know this. I'm almost certain in a few years my son will be able to answer this question once I teach him to code.

Btw the position I'm interview them for is a senior position.

QUOTE
Wise words from who I call my mentor:
*
Your mentor is wise biggrin.gif

QUOTE(flashang @ Sep 7 2021, 12:27 PM)
Beside show problem asking for solution,
You may show the code and ask what is the output ?

Should be html + css + js question, for web frontend.

Some example just for reference :
https: // fullgrade.com/tutor-problem/what-is-the-output-of-the-code/

smile.gif
*
I have questions like these if they pass the coding part. Give them some code that has some problems/errors in it, and see if they can spot it.
FlierMate
post Sep 8 2021, 01:57 PM

On my way
****
Validating
515 posts

Joined: Nov 2020
Set this skill test aside, I recall famous quote from a self-help book many years ago, where it says:

"Hire for attitude, train for skill"

It literally means skill can be trained, but not so with an employee's attitude.
So, does employer like that of @silverhawk, emphasizing on a candidate's attitude even for a technical role?

I am in my forties, and long left the IT job industry. Just curious to know what's up in today IT hiring process.
Take me as an example, I was known for bad temper as a software developer in the early millennium and despite my good skill, I was fired on one occasion after threatening to hurt a coworker in the workplace.
malleus
post Sep 8 2021, 09:09 PM

Look at all my stars!!
*******
Senior Member
2,096 posts

Joined: Dec 2011
QUOTE(FlierMate @ Sep 8 2021, 01:57 PM)
Set this skill test aside, I recall famous quote from a self-help book many years ago, where it says:

"Hire for attitude, train for skill"

It literally means skill can be trained, but not so with an employee's attitude.
So, does employer like that of @silverhawk, emphasizing on a candidate's attitude even for a technical role?

I am in my forties, and long left the IT job industry. Just curious to know what's up in today IT hiring process.
Take me as an example, I was known for bad temper as a software developer in the early millennium and despite my good skill, I was fired on one occasion after threatening to hurt a coworker in the workplace.
*
skills can be trained, yes. however there's still a minimal amount of skill requirement for each role level that you're hiring for. and it's not like this is some ultra difficult question to begin with.

if at a candidate at a senior level cannot even do a question that a first year uni student is expected to be able to do without flunking out, then there's still a problem with the aptitude to begin with.

but one test that we do find useful as a basic proficiency test will be Pivotal Lab's RPI test. it's a simple enough pairing exercise that can be completed in under an hour, there's 2 main conditions to the test,: 1) the test cases needs to be written out first
2) the candidate does not get to type. instead the candidate is to verbalise what they want to do and the pairing interviewer will be doing the typing.

it's a good test on communication skills, as well as forces the candidate to first think about testing.

even for senior or higher level candidates, it's amazing how many of them tends to trip over it, mainly due to over confidence and halfway through find themselves in trouble.

This post has been edited by malleus: Sep 8 2021, 09:23 PM
TSsilverhawk
post Sep 8 2021, 11:25 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(FlierMate @ Sep 8 2021, 01:57 PM)
Set this skill test aside, I recall famous quote from a self-help book many years ago, where it says:

"Hire for attitude, train for skill"

It literally means skill can be trained, but not so with an employee's attitude.
So, does employer like that of @silverhawk, emphasizing on a candidate's attitude even for a technical role?

I am in my forties, and long left the IT job industry. Just curious to know what's up in today IT hiring process.
Take me as an example, I was known for bad temper as a software developer in the early millennium and despite my good skill, I was fired on one occasion after threatening to hurt a coworker in the workplace.
*
Attitude is actually the most important criteria. Our questions are not particularly difficult, but normally just difficult or vague enough so that you ask questions to clarify or seek help when you need it. So based on how you ask questions and communicate, we can see the attitude.

I do have more advanced questions specific to the tech stack/language if the candidate breezes through the coding section. Once again, because I want to see how the candidate would communicate.

However like @malleus said, there needs to be some basic level of proficiency. You wouldn't hire a 5 year old even though could train them young... laugh.gif
Szzz
post Sep 9 2021, 06:36 AM

Getting Started
**
Junior Member
119 posts

Joined: Dec 2006
I remember doing this at Uni laugh.gif

Good times
twigky
post Sep 10 2021, 05:41 AM

Getting Started
**
Junior Member
59 posts

Joined: Jun 2009


I like this post.
Very interesting topic, I believe it started with about the logical and quality of many software engineers out there, but it seems end up with everyone share their answer about how to solve the problem. biggrin.gif

My opinion, interview is a very complicated process... especially you technical interview. Imagine you interview 2 candidates, one using very simple nested loop to solve the problem, another one using the assembly way to solve the problem. When both of them solve the problem with their way, how you rate both of them? Maybe in term of technical the assembly guy looks advance, but would you hire someone who can build code that most others can't really understand or read?

Share your thought. smile.gif
TSsilverhawk
post Sep 10 2021, 11:03 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(twigky @ Sep 10 2021, 05:41 AM)
I like this post.
Very interesting topic, I believe it started with about the logical and quality of many software engineers out there, but it seems end up with everyone share their answer about how to solve the problem. biggrin.gif

My opinion, interview is a very complicated process... especially you technical interview. Imagine you interview 2 candidates, one using very simple nested loop to solve the problem, another one using the assembly way to solve the problem. When both of them solve the problem with their way, how you rate both of them? Maybe in term of technical the assembly guy looks advance, but would you hire someone who can build code that most others can't really understand or read?

Share your thought. smile.gif
*
Normally nobody will use assembly in an interview laugh.gif

Questions further down the line will separate the candidates. The "answer" is less important than how you come to the answer. In a previous answer, I mentioned that we see how the candidate communicates. However, we also see how you write the code. There is a reason why you are asked to write on a whiteboard, or in a remote interview, share your screen.

How you write your code, reveals your thought process.
flashang
post Sep 10 2021, 04:28 PM

Getting Started
**
Junior Member
175 posts

Joined: Aug 2021


QUOTE(twigky @ Sep 10 2021, 05:41 AM)
I like this post.
Very interesting topic, I believe it started with about the logical and quality of many software engineers out there, but it seems end up with everyone share their answer about how to solve the problem. biggrin.gif

My opinion, interview is a very complicated process... especially you technical interview. Imagine you interview 2 candidates, one using very simple nested loop to solve the problem, another one using the assembly way to solve the problem. When both of them solve the problem with their way, how you rate both of them? Maybe in term of technical the assembly guy looks advance, but would you hire someone who can build code that most others can't really understand or read?

Share your thought. smile.gif
*
Interview is not just one question / single type of question.

It might comes with non-skill related question,

or a series of related question, some real issues happened before,
to see how the candidate solve the problem.
You might able to estimate their knowledge or skill level.

On the other side,
the candidate might also have their concern,
job scope, responsibilities, who are in the team,
is this environment suitable for them ?

smile.gif


shinichi88
post Sep 10 2021, 04:38 PM

Holy Crusader
*****
Senior Member
939 posts

Joined: Sep 2005
From: Selangor
QUOTE(silverhawk @ Aug 31 2021, 01:23 AM)
You can't master anything without understanding some of the basic foundation/fundamentals. If that is all they got, they are at risk of being automated away by AI
*
True..
Still remember my old days in Uni.
The lecturer forces us to complete every single question in the Fundamental of C++ thick textbook for our daily homework.
Glad that I when through that process.
lolzcalvin
post Sep 10 2021, 07:41 PM

shibe in predicament
******
Senior Member
1,286 posts

Joined: Mar 2014
From: 75°26'11.6"S, 136°16'16.0"E


BRUH. I'm a TypeScript dev with 3 years experience and the question actually also tricks me a bit. I at first ended up with "1 2 3 4" then "2 3 4" then so on haha. Tricky. Good warmup really..

https://tsplay.dev/we0qXW


Advent Syracuase
post Sep 12 2021, 01:42 PM

New Member
*
Junior Member
49 posts

Joined: Feb 2006
Wasn't that difficult

CODE
const countToTarget = (target) => {
   let current = 1;
   const output_array = [];
   while(current <= target) {
       output_array.push(current);
       current++;
   }
   return output_array.join(' ');
}


Did you guys use paper? It always trips me off when I have to use paper to code. There was once I got an interview in a semi con company. They asked me to write solutions for code problems in a paper [???].
malleus
post Sep 12 2021, 04:50 PM

Look at all my stars!!
*******
Senior Member
2,096 posts

Joined: Dec 2011
QUOTE(Advent Syracuase @ Sep 12 2021, 01:42 PM)
Wasn't that difficult

CODE
const countToTarget = (target) => {
   let current = 1;
   const output_array = [];
   while(current <= target) {
       output_array.push(current);
       current++;
   }
   return output_array.join(' ');
}


Did you guys use paper? It always trips me off when I have to use paper to code. There was once I got an interview in a semi con company. They asked me to write solutions for code problems in a paper [???].
*
I scribble stuff on paper first whenever I'm able to.
TSsilverhawk
post Sep 12 2021, 11:30 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(Advent Syracuase @ Sep 12 2021, 01:42 PM)
Wasn't that difficult

CODE
const countToTarget = (target) => {
   let current = 1;
   const output_array = [];
   while(current <= target) {
       output_array.push(current);
       current++;
   }
   return output_array.join(' ');
}


Did you guys use paper? It always trips me off when I have to use paper to code. There was once I got an interview in a semi con company. They asked me to write solutions for code problems in a paper [???].
*
Your code would only print a single line
https://jsfiddle.net/Lh07pfmx/

Do I always use paper? No, but I use the whiteboard a lot, especially when it comes to drawing a rough flowchart of how the logic should work across the various components. Some pseudocoding on a whiteboard is also a good first pass before trying to write it in its actual language.

Its very common in tech interviews to have candidates use a whiteboard to write the code, so not much different from paper.

Advent Syracuase
post Sep 13 2021, 05:38 PM

New Member
*
Junior Member
49 posts

Joined: Feb 2006
Woopsies, here's the fixed version

CODE
const countToTarget = (target) => {
 let current = 1;
 const output_array = [];
 while (current <= target) {
   output_array.push(current);
   current++;
 }
 [...output_array].forEach((ele) => {
   console.log(output_array.join(" "));
   output_array.pop();
 });
};


Not optimized tho. Should have a better way. What i mean by paper is like writing the actual code on paper. Showing thought process via paper/whiteboard is fine
lolzcalvin
post Sep 17 2021, 02:15 AM

shibe in predicament
******
Senior Member
1,286 posts

Joined: Mar 2014
From: 75°26'11.6"S, 136°16'16.0"E


QUOTE(lolzcalvin @ Sep 10 2021, 07:41 PM)
BRUH. I'm a TypeScript dev with 3 years experience and the question actually also tricks me a bit. I at first ended up with "1 2 3 4" then "2 3 4" then so on haha. Tricky. Good warmup really..

https://tsplay.dev/we0qXW
*
decided to revisit this question to see how far I can go hmm.gif
tried to memoise previous string and trims them afterwards. put some time complexity identification, not sure correct or not..long time no touch time complexity stuffs le

edit 2022: just realised my recursion string manipulation method didn't take account of 2 digits and more. updated (also with benchmarked result)

https://tsplay.dev/mMx01N

This post has been edited by lolzcalvin: Mar 17 2022, 04:12 PM
FlierMate
post Sep 18 2021, 06:58 PM

On my way
****
Validating
515 posts

Joined: Nov 2020
QUOTE(silverhawk @ Aug 28 2021, 07:17 PM)
Nah, give you something fun: https://leetcode.com/
*
(Sorry for reviving this topic again)

I stop playing with LeetCode after having been downvoted multiple times with -8 reputation.

user posted image

My bad for joking around and solving problems with difficult-to-understand solution.

user posted image

Even one member was amazed at me for getting downvotes multiple times:

user posted image

Well, it was two years ago. Forgive but not forget.
Grammar Police
post Sep 20 2021, 01:15 AM

Casual
***
Junior Member
332 posts

Joined: Mar 2016
https://www.reddit.com/r/ProgrammerHumor/co...on_dating_apps/

maybe relevant to this thread
malleus
post Sep 20 2021, 08:59 AM

Look at all my stars!!
*******
Senior Member
2,096 posts

Joined: Dec 2011
QUOTE(Grammar Police @ Sep 20 2021, 01:15 AM)
I don't think much of the algorithm questions myself, but do keep in mind that the question given in this thread is to do with basic array operations that a first year uni student is expect to be able to solve. In fact, this tends to be lab questions given to a uni student in the first half of the first semester.


TSsilverhawk
post Sep 20 2021, 10:52 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(Grammar Police @ Sep 20 2021, 01:15 AM)
Seen this circling around.

My response to this is "So what?". Did that person write the app from scratch and deploy the infra themselves? No, they were likely a part of a huge team. The experience says nothing about your ability to code, its quality, or problem solving ability. Just because that person worked on a project, doesn't tell us anything. Many of the interview candidates I went through were senior/lead positions from well known companies.

The code test is actually the final portion of the interview. Before that we tend to ask about your experience and let you elaborate on it. So like in the example in the link, we would ask what did the candidate contribute to that project, probe a bit about the workings of the product just to see what the candidate knows (BS detector).

I personally like to ask candidates about their proudest moments in their current job or career lifetime and let them tell their story.

P.S. - I don't use algorithm questions because people can study for it, I rather throw them a simple problem / puzzle and see how their brains work.

This post has been edited by silverhawk: Sep 20 2021, 10:54 AM
ngaisteve1
post Sep 24 2021, 09:43 AM

Software Engineer
*******
Senior Member
6,779 posts

Joined: Dec 2005
From: Kuala Lumpur


QUOTE(silverhawk @ Aug 26 2021, 08:28 PM)
There are some positions open in the company at the moment, so been doing some interviews. We have a warm-up question for the code whiteboarding session that goes like something like this

CODE

Write a function that takes an input number (e.g. 4) and prints:
1 2 3 4
1 2 3
1 2
1


and 90% of the candidates are failing this. All of the frontend candidates could not do this, even after some guidance. The opening is for a senior position with at least 5 years experience. While ability to answer the questions does not determine whether you get the offer or not, I find it quite odd that the warmup question is tripping people up.

Is anyone else facing this issue with their hiring? Should this level of problem solving ability not be expected of frontend devs?
*
Really? I want to apply already biggrin.gif

My version in C#

CODE

       [Theory(DisplayName = "Print numbers")]
       [InlineData("4", "1 2 3 4 \r\n1 2 3 \r\n1 2 \r\n1 \r\n")]
       [InlineData("1", "")]
       [InlineData("0", "")]
       [InlineData("four", "")]
       public void GivenANumber_WhenRun_ShouldReturnStringOfNumbers(string n, string expectedResult)
       {
           // Act
           var actualResult = PrintNumbers(n);

           // Assert
           Assert.Equal(expectedResult, actualResult);
       }

       public static string PrintNumbers(string n)
       {
           if(string.IsNullOrEmpty(n)) return string.Empty;

           var isInteger = int.TryParse(n, out int row);

           if (!isInteger) return string.Empty;

           if (row <= 1) return string.Empty;

           var sb = new StringBuilder();
           for (int x = row; x > 0; x--)
           {
               for (int y = 1; y <= x; y++)
               {
                   sb.Append(y + " ");
               }
               sb.AppendLine();
           }

           return sb.ToString();
       }

Test result: 4 Passed

My initial parameter type is int. But then what if the input is string, it will break. For me, I will share a few ways which I will be using. My initial version is without stringbuilder. It just print on the fly. But, I would prefer a pure method which is easier to test. So, I implement StringBuilder and it is also better for performance and string is not suitable not mutation purpose. Then I will add on that the con of this method is because it is using classic for loop, the code is not 'functional' programming. This means it will prone to error if we are not careful with the loop counter. But the pro is speed and readablity. I think I can refactor it to LINQ to make it more "functional programming" but its performance and readability is still okay. And to also improve a better naming for the method name.

If input has to be integer type and to print the output in the method directly, this is another variation. It uses different way to store data. Instead of using StringBuilder, we can use array to store the data.

CODE

public static void PrintNumbersWithArray(int row)
{
 if (row <= 1) return;
 var arrayNumbers = Enumerable.Range(1, row).Select(x => x).ToArray();
 for (int i = arrayNumbers.Length; i > 0; i--)
 {
  Console.WriteLine(string.Join(" ", arrayNumbers[..i]));
 }
}


This post has been edited by ngaisteve1: Sep 24 2021, 02:00 PM
angch
post Sep 24 2021, 02:10 PM

On my way
****
Junior Member
559 posts

Joined: Jul 2006
WHHHHHEEE! It's code golfing time! Sorry, offtopic.

CODE

~/build/golf$ cat golf.pl
@_=(1..<>);while(@_){print join(" ",@_),"\n";pop@_}
~/build/golf$ perl golf.pl
5
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1


52 bytes!

CODE
$_=<>;print join" ",(1..$_--),"\n"while$_;


43 bytes!

This post has been edited by angch: Sep 24 2021, 03:25 PM
TSsilverhawk
post Sep 24 2021, 02:57 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(angch @ Sep 24 2021, 02:10 PM)
WHHHHHEEE! It's code golfing time! Sorry, offtopic.

CODE

~/build/golf$ cat golf.pl
@_=(1..<>);while(@_){print join(" ",@_),"\n";pop@_}
~/build/golf$ perl golf.pl
5
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1


52 bytes!
*
PERL was the first language I learnt... thanks for reminding me why its also known as Pathologically Eclectic Rubbish Lister laugh.gif
Find The Way
post Oct 8 2021, 07:40 PM

Enthusiast
*****
Senior Member
724 posts

Joined: Nov 2004


QUOTE(silverhawk @ Aug 27 2021, 12:59 AM)
Pretty much my thoughts, but these are people working in rather reputable companies, some are even leading teams! I'm honestly baffled
...
...
*
If it's not sensitive, may I know which reputable companies?

This post has been edited by Find The Way: Oct 9 2021, 12:56 AM
TSsilverhawk
post Oct 10 2021, 01:40 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(Find The Way @ Oct 8 2021, 07:40 PM)
If it's not sensitive, may I know which reputable companies?
*
The fact that I didnt reveal from the beginning should give you a hint
Find The Way
post Oct 10 2021, 11:07 AM

Enthusiast
*****
Senior Member
724 posts

Joined: Nov 2004


QUOTE(silverhawk @ Oct 10 2021, 01:40 AM)
The fact that I didnt reveal from the beginning should give you a hint
*
I was betting with my luck tongue.gif
stargamer
post Mar 15 2022, 11:11 PM

Getting Started
**
Junior Member
279 posts

Joined: Aug 2007
not that hard.. manage to do it in like a few minutes

const test = function(num) {
let numbers = [];
for (let i = 1; i <= num + 1; i++) {
numbers.push(i);
// console.log(numbers);
}

for (let i = 1; i <= num; i++) {
numbers.pop();
console.log(numbers);
}
};

console.log(test(4));
stargamer
post Mar 16 2022, 11:17 AM

Getting Started
**
Junior Member
279 posts

Joined: Aug 2007
heres how to do it with strings

const test2 = function(num) {
let numbers = '';
let result = '';
for (let i = 1; i <= num + 1; i++) {
numbers += i;
// console.log(numbers);
}
for (let i = numbers.length - 1; i >= 0; i--) {
result = numbers.slice(0, i);
console.log(result);
}
};

test2(4);
TSsilverhawk
post Mar 16 2022, 11:48 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(stargamer @ Mar 15 2022, 11:11 PM)
not that hard.. manage to do it in like a few minutes
» Click to show Spoiler - click again to hide... «

*
If we assume console.log can only log strings and not arrays, how would you change your code?


QUOTE(stargamer @ Mar 16 2022, 11:17 AM)
heres how to do it with strings
» Click to show Spoiler - click again to hide... «

*
This will fail if I gave you a number that's larger than 1 digit. Also the spacing between the numbers is missing.
stargamer
post Mar 17 2022, 10:00 AM

Getting Started
**
Junior Member
279 posts

Joined: Aug 2007
QUOTE(silverhawk @ Mar 16 2022, 11:48 PM)
If we assume console.log can only log strings and not arrays, how would you change your code?
This will fail if I gave you a number that's larger than 1 digit. Also the spacing between the numbers is missing.
*
how to do that with strings?
TSsilverhawk
post Mar 17 2022, 10:09 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(stargamer @ Mar 17 2022, 10:00 AM)
how to do that with strings?
*
console.log already logs strings for you, as per your 2nd example. If you pass it an array/object, it converts it into a string for output for you, which is convenient. However now assume it can't do that, and you have to pass in the string/numbers manually to build the output. How would you change your code to accommodate that?
stargamer
post Mar 17 2022, 10:37 AM

Getting Started
**
Junior Member
279 posts

Joined: Aug 2007
QUOTE(silverhawk @ Mar 17 2022, 10:09 AM)
console.log already logs strings for you, as per your 2nd example. If you pass it an array/object, it converts it into a string for output for you, which is convenient. However now assume it can't do that, and you have to pass in the string/numbers manually to build the output. How would you change your code to accommodate that?
*
No idea , show me please
angch
post Mar 17 2022, 11:54 AM

On my way
****
Junior Member
559 posts

Joined: Jul 2006
It's a very roundabout way to ask what is
CODE
.join
, which I used in my Perl solution.

CODE
a = [1, 2, 3]
console.log(a.join(", "));


It's Javascript, so there's tricks you can do with
CODE
JSON.stringify
as well. (Ok, maybe not for this question)

This post has been edited by angch: Mar 17 2022, 12:07 PM
TSsilverhawk
post Mar 17 2022, 02:29 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(stargamer @ Mar 17 2022, 10:37 AM)
No idea , show me please
*
read through the topic, got plenty of examples actually
stargamer
post Mar 17 2022, 09:11 PM

Getting Started
**
Junior Member
279 posts

Joined: Aug 2007
QUOTE(silverhawk @ Mar 17 2022, 02:29 PM)
read through the topic, got plenty of examples actually
*
const createRow2 = number => {
let string = '';
for (let i = 1; i <= number; i++) {
if (i === 1) {
string += i;
} else {
string += ' ' + i;
}
}
return string;
};

const printAll2 = number => {
let string = '';
for (let i = number; i >= 1; i--) {
if (i === number) {
string += createRow2(i);
} else {
string += '\n' + createRow2(i);
}
}
console.log(string);
};

printAll2(12);
DoomCognition
post Mar 22 2022, 03:18 PM

Enthusiast
*****
Junior Member
700 posts

Joined: Nov 2010


QUOTE(silverhawk @ Aug 26 2021, 07:28 PM)
There are some positions open in the company at the moment, so been doing some interviews. We have a warm-up question for the code whiteboarding session that goes like something like this

CODE

Write a function that takes an input number (e.g. 4) and prints:
1 2 3 4
1 2 3
1 2
1


and 90% of the candidates are failing this. All of the frontend candidates could not do this, even after some guidance. The opening is for a senior position with at least 5 years experience. While ability to answer the questions does not determine whether you get the offer or not, I find it quite odd that the warmup question is tripping people up.

Is anyone else facing this issue with their hiring? Should this level of problem solving ability not be expected of frontend devs?
*
It is the same with backend devs. Similar everywhere. I have a few hypothesis on this, not sure whether they are true. But what is true is that today, the supply of good developers is a lot smaller than the demand.
wahidzeb
post Mar 22 2022, 03:26 PM

New Member
*
Junior Member
44 posts

Joined: Feb 2017


QUOTE(silverhawk @ Aug 26 2021, 07:28 PM)
There are some positions open in the company at the moment, so been doing some interviews. We have a warm-up question for the code whiteboarding session that goes like something like this

CODE

Write a function that takes an input number (e.g. 4) and prints:
1 2 3 4
1 2 3
1 2
1


and 90% of the candidates are failing this. All of the frontend candidates could not do this, even after some guidance. The opening is for a senior position with at least 5 years experience. While ability to answer the questions does not determine whether you get the offer or not, I find it quite odd that the warmup question is tripping people up.

Is anyone else facing this issue with their hiring? Should this level of problem solving ability not be expected of frontend devs?
*
public class MyClass {
public static void main(String args[]) {
int number = 4;
for (int i = 0 ; i < number ; number--)
{
for (int j = 1 ; j <= number; j++){
System.out.print(j+" ");
}
System.out.println();}
}
}
TSsilverhawk
post Mar 22 2022, 05:06 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(DoomCognition @ Mar 22 2022, 03:18 PM)
It is the same with backend devs. Similar everywhere. I have a few hypothesis on this, not sure whether they are true. But what is true is that today, the supply of good developers is a lot smaller than the demand.
*
Yes, got quite a few backend guys failing this too, but so far not as bad as the frontend candidates.

Good devs definitely less than demand, but teruk also can't be this teruk right? At this point might as well hire fresh grads
DoomCognition
post Mar 22 2022, 09:02 PM

Enthusiast
*****
Junior Member
700 posts

Joined: Nov 2010


QUOTE(silverhawk @ Mar 22 2022, 05:06 PM)
Yes, got quite a few backend guys failing this too, but so far not as bad as the frontend candidates.

Good devs definitely less than demand, but teruk also can't be this teruk right? At this point might as well hire fresh grads
*
Of yes, they are actually bad.

I interviewed many junior candidates recently. Claim they got SQL, C++, etc. Claim their skill are 3 or 4 or 5, but when we actually test it, it is shit. Many even dare to put C++ as 3, but when we ask, they then reveal that they have only taken a course in university, and that makes them a 3. Really facepalm.

The simple test that we prepared, most can't even answer 25% of it. The idea is just to test if they can do basic stuff, especially in data manipulation with SQL. But all really hopeless. Please la, if cannot even do proper select, where, group by, join or count, better don't put SQL as 2. Just put 1.

The recent freahies (up to 3y experience) are honestly just terrible for technical roles. They are only interested in analytics, and everyone just want to be data scientist. But when asked how to get data, all expect it to magically appear in a nice Power BI dashboard for them to do analytics.

Honestly, if I already have a nice dashboard with the backend completely lined up, I don't need these freahies as data scientist. Might as well get my existing colleagues to do analytics, and produce results. After all, the heavy lifting has been done.

I think a few factors make the situation like this.

1. Good ones left for SG, at least those who can uproot and leave.
2. The remaining good ones who can't uproot, are fully taken in by Tier 1 companies. Even then, there is not enough to go around up to this point.
3. Most freshies don't bother on technicals now, don't want to do the hard work. Just want to prepare slides and do 'analytics'.
4. Technical field in Malaysia don't pay in the past, and there is no appreciation for good devs. STEM is just very weak in Malaysia, everyone only want to do business and social science field like economy, accounting, finance, etc. Resultantly, 99% of senior management in companies don't have STEM background and don't appreciate STEM related stuff like tech. Their expectations does not align with reality, and don't understand that no amount of pushing can make things move faster if there is no proficiency. So we are left with a downtrend cycle.

I say this as a novice programmer. I don't consider myself good, but the surprising thing is most of them are worse than me. And no, my main job is not a programmer but a business/functional person.

user posted image
TSsilverhawk
post Mar 23 2022, 12:12 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(DoomCognition @ Mar 22 2022, 09:02 PM)
» Click to show Spoiler - click again to hide... «

*
Junior teruk I can understand, I've been interviewing for senior positions. Mau muntah puke.gif

Also been telling people not to put proficiency levels for tech/skills cause its so subjective and typically works against you. E.g. if you put low then interviewer will think you suck/no confidence. If you put high, it may not be as high as interviewer think it is. Either way also stab yourself.
System Error Message
post Mar 27 2022, 12:28 AM

Regular
******
Senior Member
1,779 posts

Joined: Jul 2010
QUOTE(silverhawk @ Aug 27 2021, 12:59 AM)
Pretty much my thoughts, but these are people working in rather reputable companies, some are even leading teams! I'm honestly baffled
Don't feel bad, even we don't expect people to get it immediately. We just want to see how you think and come to a solution. You came to a solution, so all is good smile.gif

Technically, double loops are not necessary, its just the most straight forward way. Its possible to do it in a single loop. Want to give that a go? biggrin.gif
Its meant to be simple, suppose to warm you up and get you comfortable for the harder questions down the road.
*
Actually you can't spot a fake on the resume or such. My part time has to hire university students (its a rule for gov funding), as in people still studying but part time. I was the one interviewing and i set up a trick question. Its easy but tricky something that no frontend dev could do because frontend languages do not support the solution. This seems very easy to do even in a single loop with few branches. Maybe i'll give this ago later with my expert algorithmic knowledge.

The exercise i usually give is something like "write a program that searches for the inputted text in files in the given directory and use modern features". Everyone fails this even those who were ahead of me when i wrote the solution. For reference i wrote the solution while i was 1st year at university for fun because i couldn't figure out how to use grep. It was faster than windows 7 search at the time and scales well with todays hardware but my point is that, programmers today do not think about design and its a bad idea to give limited time to code. years ago, to work for amazon they gave you a take home exercise like i do today with this and i gave my friend my solution and he got in easy. Compared to today you get 2 hours only in coding tests to join amazon and the answers are from leetcode, so my better answers are considered wrong today even when they scale better such as if you did run them on 64 core machines with raid nvme drives with large datasets. Such a small simple exercise can have a large impact if the solution is good.

The modern features part is why frontend languages cannot do this. When coding is taught online or in classes, people don't bother to teach you how to design the flow of your code and understanding how code runs. Good CS courses actually cover this while many universities that teach CS dont even teach this properly.
System Error Message
post Mar 27 2022, 12:38 AM

Regular
******
Senior Member
1,779 posts

Joined: Jul 2010
QUOTE(DoomCognition @ Mar 22 2022, 09:02 PM)
Of yes, they are actually bad.

I interviewed many junior candidates recently. Claim they got SQL, C++, etc. Claim their skill are 3 or 4 or 5, but when we actually test it, it is shit. Many even dare to put C++ as 3, but when we ask, they then reveal that they have only taken a course in university, and that makes them a 3. Really facepalm.

The simple test that we prepared, most can't even answer 25% of it. The idea is just to test if they can do basic stuff, especially in data manipulation with SQL. But all really hopeless. Please la, if cannot even do proper select, where, group by, join or count, better don't put SQL as 2. Just put 1.

The recent freahies (up to 3y experience) are honestly just terrible for technical roles. They are only interested in analytics, and everyone just want to be data scientist. But when asked how to get data, all expect it to magically appear in a nice Power BI dashboard for them to do analytics.

Honestly, if I already have a nice dashboard with the backend completely lined up, I don't need these freahies as data scientist. Might as well get my existing colleagues to do analytics, and produce results. After all,  the heavy lifting has been done.

I think a few factors make the situation like this.

1. Good ones left for SG, at least those who can uproot and leave.
2. The remaining good ones who can't uproot, are fully taken in by Tier 1 companies. Even then, there is not enough to go around up to this point.
3. Most freshies don't bother on technicals now, don't want to do the hard work. Just want to prepare slides and do 'analytics'.
4. Technical field in Malaysia don't pay in the past, and there is no appreciation for good devs. STEM is just very weak in Malaysia, everyone only want to do business and social science field like economy, accounting, finance, etc. Resultantly, 99% of senior management in companies don't have STEM background and don't appreciate STEM related stuff like tech. Their expectations does not align with reality, and don't understand that no amount of pushing can make things move faster if there is no proficiency. So we are left with a downtrend cycle.

I say this as a novice programmer. I don't consider myself good, but the surprising thing is most of them are worse than me. And no, my main job is not a programmer but a business/functional person.

user posted image
*
This is why i gave up coding. Pay and treatment were bad, no consideration for ethics. For instance for me to be productive i had to nap during office hours, which also helped me tackle coding problems, not to mention it helps when i'm not feeling ok, but you can imagine how other people view this.

This is why i have trouble working in malaysia, i consider quality important and consider that we treat our customers well and actually give them what they paid for. In many places i worked, customers never got what they paid for. For example customer paid for hosting and only got outdated hardware (gen1 iseries xeons) that could handle 1500 users (not even the 2.5k/s user actions they spec). When i came in i did quite a lot of design and R&D that would be easy to maintain and handle that, but all of it got rejected and to top it off my boss having admin background in webservers, couldn't figure out the simple basics of why whenever he set up the VMs to test that it was so slow (hint: you can't oversubscribe RAM with any modern OS) and 3rd party refused to support my setup when they should've just been renegotiated and reduced to only supporting code that they wrote (they are considered aws certified but their aws designs don't work with the software they are writing and its an australian company). Because i needed sleep i ended up sleeping on the server room floor but ended up being fired for all sorts of reasons. I did deliver but they kept rejecting and refusing to listen.

Also don't bother with powerBI. matlab chad tongue.gif . If people wanna be data scientist, tell them to do python GPU and matlab tongue.gif .
FlierMate
post Mar 27 2022, 05:09 AM

On my way
****
Validating
515 posts

Joined: Nov 2020
@System Error Message, you seem like a knowledgeable person in software job industry but it is sad to see you giving up on coding.
You can try become mentor or tutor.

System Error Message
post Mar 28 2022, 01:00 AM

Regular
******
Senior Member
1,779 posts

Joined: Jul 2010
QUOTE(FlierMate @ Mar 27 2022, 05:09 AM)
@System Error Message, you seem like a knowledgeable person in software job industry but it is sad to see you giving up on coding.
You can try become mentor or tutor.
*
well i'm unemployed and broke at the moment and the future seems bleak for me.
ragk
post Mar 28 2022, 02:54 PM

BooBoo~
*******
Senior Member
2,241 posts

Joined: Apr 2009


Just curious, for interviewer like u guy, what's the main differ of backend and frontend for u guy?
I'm mostly on backend, but I did help our frontend guy when im free, mostly work with angular, react and typescript, does that already make me qualified as a front end dev? (but i have to admit it took me sometimes to adjust CSS)

This post has been edited by ragk: Mar 28 2022, 02:54 PM
ProSuperSchool
post Mar 28 2022, 05:25 PM

Casual
***
Junior Member
476 posts

Joined: Aug 2021


Which one easier to start first? Front end??
System Error Message
post Mar 28 2022, 05:34 PM

Regular
******
Senior Member
1,779 posts

Joined: Jul 2010
QUOTE(ragk @ Mar 28 2022, 02:54 PM)
Just curious, for interviewer like u guy, what's the main differ of backend and frontend for u guy?
I'm mostly on backend, but I did help our frontend guy when im free, mostly work with angular, react and typescript, does that already make me qualified as a front end dev? (but i have to admit it took me sometimes to adjust CSS)
*
angular, react and typescript are not backend languages, well not to me. To me they are disgusting frontend systems with very limited lifespans. Take react for instance, if theres an update, you may need to rewrite your application from scratch.
TSsilverhawk
post Mar 29 2022, 03:35 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(ragk @ Mar 28 2022, 02:54 PM)
Just curious, for interviewer like u guy, what's the main differ of backend and frontend for u guy?
I'm mostly on backend, but I did help our frontend guy when im free, mostly work with angular, react and typescript, does that already make me qualified as a front end dev? (but i have to admit it took me sometimes to adjust CSS)
*
If I were to put it in a very simple generic way

FrontEnd - User Experience
Backend - Data flow

So while you may be able to do some code for the frontend, unless you understand user experience and make it a part of how you solve frontend problems, I don't consider you a frontend developer. For example, forcing a user to use a specific browser is a bad user experience.




Find The Way
post Apr 2 2022, 04:01 AM

Enthusiast
*****
Senior Member
724 posts

Joined: Nov 2004


Just my deduction as a back-end guy, for silverhawk's original question:

Why it happens more often to front-end dev interviewees?
My context:
1. Few months ago I started to touch front-end development with react framework for my personal project. So far I haven't get to implement any data structure based logic (limited experience, my use cases could be in-comprehensive)
2. On my last job, once, I tried to debug front-end issue for the first time as project's front-end dev was on vacation. I was shocked when I saw the project's implementation. The in-house proprietary framework was designed in such a way that most projects' front-end work requires only IF-ELSE, no iteration logic is needed.

My deduction:
- If a front-end candidate has been doing this kind of works all along, and he/she didn't do any project of different nature outside of their job, more likely they will perform weaker in data structure based problem. In fact I believe not many front-end dev from my last company is able answer this kind of question. Of course, front-end guys may face unique challenge, such as browser type/version compatibility issue.

How can this happen to candidates who working in reputable companies?
Possibilities: whenever a company going through rapid expansion,
- hiring managers might lower the hiring bar down to meet the expansion goal, if they can't find enough qualified candidates.
- there might not be enough qualified interviewers
This deduction is based on a past experience where my manager was assigned KPI goal by engineering director, to expand a 25-engineers team to 70 people within 6 months. Quite a few new team members from that hiring drive gave us headache later on. (I don't mean I worked in a "reputable company", but similar issue can be there)

This post has been edited by Find The Way: Apr 2 2022, 04:06 AM
flashang
post Apr 2 2022, 03:46 PM

Getting Started
**
Junior Member
175 posts

Joined: Aug 2021


QUOTE(Find The Way @ Apr 2 2022, 04:01 AM)
Just my deduction as a back-end guy, for silverhawk's original question:

Why it happens more often to front-end dev interviewees?
My context:
1. Few months ago I started to touch front-end development with react framework for my personal project. So far I haven't get to implement any data structure based logic (limited experience, my use cases could be in-comprehensive)
2. On my last job, once, I tried to debug front-end issue for the first time as project's front-end dev was on vacation. I was shocked when I saw the project's implementation. The in-house proprietary framework was designed in such a way that most projects' front-end work requires only IF-ELSE, no iteration logic is needed.

My deduction:
- If a front-end candidate has been doing this kind of works all along, and he/she didn't do any project of different nature outside of their job, more likely they will perform weaker in data structure based problem. In fact I believe not many front-end dev from my last company is able answer this kind of question. Of course, front-end guys may face unique challenge, such as browser type/version compatibility issue.

How can this happen to candidates who working in reputable companies?
Possibilities: whenever a company going through rapid expansion,
- hiring managers might lower the hiring bar down to meet the expansion goal, if they can't find enough qualified candidates.
- there might not be enough qualified interviewers
This deduction is based on a past experience where my manager was assigned KPI goal by engineering director, to expand a 25-engineers team to 70 people within 6 months. Quite a few new team members from that hiring drive gave us headache later on. (I don't mean I worked in a "reputable company", but similar issue can be there)
*
This could be "if it ain't broke, don't fix it", or "don't reinvent the wheel" mindset.
Since if-else is working, copy-paste and update the different will be a quick and easy update.

Tester may only need to confirm the app UI flow is correct, bugs free and smooth.
If there is no user complain, who care about it ?

hmm.gif


TSsilverhawk
post Apr 2 2022, 06:43 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(Find The Way @ Apr 2 2022, 04:01 AM)
Just my deduction as a back-end guy, for silverhawk's original question:

Why it happens more often to front-end dev interviewees?
My context:
1. Few months ago I started to touch front-end development with react framework for my personal project. So far I haven't get to implement any data structure based logic (limited experience, my use cases could be in-comprehensive)
2. On my last job, once, I tried to debug front-end issue for the first time as project's front-end dev was on vacation. I was shocked when I saw the project's implementation. The in-house proprietary framework was designed in such a way that most projects' front-end work requires only IF-ELSE, no iteration logic is needed.

My deduction:
- If a front-end candidate has been doing this kind of works all along, and he/she didn't do any project of different nature outside of their job, more likely they will perform weaker in data structure based problem. In fact I believe not many front-end dev from my last company is able answer this kind of question. Of course, front-end guys may face unique challenge, such as browser type/version compatibility issue.

How can this happen to candidates who working in reputable companies?
Possibilities: whenever a company going through rapid expansion,
- hiring managers might lower the hiring bar down to meet the expansion goal, if they can't find enough qualified candidates.
- there might not be enough qualified interviewers
This deduction is based on a past experience where my manager was assigned KPI goal by engineering director, to expand a 25-engineers team to 70 people within 6 months. Quite a few new team members from that hiring drive gave us headache later on. (I don't mean I worked in a "reputable company", but similar issue can be there)
*
The thing is, I'm not even asking a data-structure question. I don't expect them to traverse a binary tree (although if they knew how it would be good). Looping through rows and columns should be a normal thing for a frontend developer. If you had to display a table from an api result, for sure you would at least do a nested loop.

This was until I interviewed some candidate that said "do you guys write your own components"? Seems like frontend devs now all just re-use existing components. You want a table, just pass the component data and it will render it, don't even need to know what a loop is!


life4
post Apr 3 2022, 11:10 AM

Getting Started
**
Junior Member
204 posts

Joined: Apr 2012
QUOTE(Find The Way @ Apr 2 2022, 04:01 AM)
Just my deduction as a back-end guy, for silverhawk's original question:

Why it happens more often to front-end dev interviewees?
My context:
1. Few months ago I started to touch front-end development with react framework for my personal project. So far I haven't get to implement any data structure based logic (limited experience, my use cases could be in-comprehensive)
2. On my last job, once, I tried to debug front-end issue for the first time as project's front-end dev was on vacation. I was shocked when I saw the project's implementation. The in-house proprietary framework was designed in such a way that most projects' front-end work requires only IF-ELSE, no iteration logic is needed.

My deduction:
- If a front-end candidate has been doing this kind of works all along, and he/she didn't do any project of different nature outside of their job, more likely they will perform weaker in data structure based problem. In fact I believe not many front-end dev from my last company is able answer this kind of question. Of course, front-end guys may face unique challenge, such as browser type/version compatibility issue.

How can this happen to candidates who working in reputable companies?
Possibilities: whenever a company going through rapid expansion,
- hiring managers might lower the hiring bar down to meet the expansion goal, if they can't find enough qualified candidates.
- there might not be enough qualified interviewers
This deduction is based on a past experience where my manager was assigned KPI goal by engineering director, to expand a 25-engineers team to 70 people within 6 months. Quite a few new team members from that hiring drive gave us headache later on. (I don't mean I worked in a "reputable company", but similar issue can be there)
*
i just curios for the expansion part . should not it be a HR KPI goal as they should help to find enough qualified candidate?
Find The Way
post Apr 3 2022, 12:44 PM

Enthusiast
*****
Senior Member
724 posts

Joined: Nov 2004


QUOTE(flashang @ Apr 2 2022, 03:46 PM)
This could be "if it ain't broke, don't fix it", or "don't reinvent the wheel" mindset.
Since if-else is working, copy-paste and update the different will be a quick and easy update.

Tester may only need to confirm the app UI flow is correct, bugs free and smooth.
If there is no user complain, who care about it ?

hmm.gif
*
What I meant is that, I didn't expect that company's front-end dev job to be that simple. There was a team in HQ dedicated for building and maintaining in-house front-end framework, it's intentional to make front-end works for business project as simple as possible. To the interest of engineer, that approach has cons and pros: it makes life very easy for front-end dev (non-framework), but it also makes them easily replaceable. Every time that company exercises restructuring or head count cut, front-end devs (non-framework) in the company got hit first, impact on back-end devs and front-end devs (framework) was usually very light or even none sometimes. Occasionally I got this feeling that in management's eyes, these front-end devs (non-framework) are more like temp/contractors.

This post has been edited by Find The Way: Apr 3 2022, 12:49 PM
Find The Way
post Apr 3 2022, 12:55 PM

Enthusiast
*****
Senior Member
724 posts

Joined: Nov 2004


QUOTE(silverhawk @ Apr 2 2022, 06:43 PM)
The thing is, I'm not even asking a data-structure question. I don't expect them to traverse a binary tree (although if they knew how it would be good). Looping through rows and columns should be a normal thing for a frontend developer. If you had to display a table from an api result, for sure you would at least do a nested loop.

This was until I interviewed some candidate that said "do you guys write your own components"? Seems like frontend devs now all just re-use existing components. You want a table, just pass the component data and it will render it, don't even need to know what a loop is!
*
What I meant by data structure, includes those simplest one like array and list. My observation is that there are three types of front-end jobs:
1. Those who build components from scratch, or at least actively maintaining components
2a. Those to use only pre-built in-house components
2b. Those to use only pre-built external or opensource components
3. Mix of (1) and (2).
For my last company, we have 10% of front-end jobs are type 1 (a dedicated team in HQ), 90% are type 2a (every other front-end dev in the org), there's no type 2b or type 3 role in the company. Advantage: easier to achieve consistency. Disadvantage: occasional bottleneck.
Find The Way
post Apr 3 2022, 01:19 PM

Enthusiast
*****
Senior Member
724 posts

Joined: Nov 2004


QUOTE(life4 @ Apr 3 2022, 11:10 AM)
i just curios for the expansion part . should not it be a HR KPI goal as they should help to find enough qualified candidate?
*
I'm not sure if that company's HR has this KPI, perhaps they do. However, if engineering team and manager keeps telling higher management that we don't have enough capacity to handle more projects, it definitely makes the manager look bad in the eyes of senior management, well... at least in that company's management culture. HR has their own standard hiring method/channel, we knew those are not enough, so engineering team will have to do extra to bridge the gap, say organising outreach events, or use some of the engineering team's budget to launch referral program, etc..
flashang
post Apr 3 2022, 02:05 PM

Getting Started
**
Junior Member
175 posts

Joined: Aug 2021


QUOTE(Find The Way @ Apr 3 2022, 12:44 PM)
What I meant is that, I didn't expect that company's front-end dev job to be that simple. There was a team in HQ dedicated for building and maintaining in-house front-end framework, it's intentional to make front-end works for business project as simple as possible. To the interest of engineer, that approach has cons and pros: it makes life very easy for front-end dev (non-framework), but it also makes them easily replaceable. Every time that company exercises restructuring or head count cut, front-end devs (non-framework) in the company got hit first, impact on back-end devs and front-end devs (framework) was usually very light or even none sometimes. Occasionally I got this feeling that in management's eyes, these front-end devs (non-framework) are more like temp/contractors.
*
A clear interface for user can access to the function fast and easy without guessing is very important.
User have no patience for a simple page load to for 10+ seconds (or may be even lesser).
Or some function hide deep inside sub-sub-sub menu / page.

For back-end dev,
basic coding on front-end to test the data integrity / conversion is very important.
At least they know what should / shouldn't expose to front-end,
the proper way to query for certain information from back-end, ...

So some company appoint graphics designer to draft layout / elements / templates,
and back-end dev applied these design and display to user.

They might using some opensource or commercial components to build the front-end,
or build in-house engine to generate layout for front-end.

sweat.gif


TSsilverhawk
post Apr 3 2022, 03:13 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(Find The Way @ Apr 3 2022, 12:55 PM)
What I meant by data structure, includes those simplest one like array and list. My observation is that there are three types of front-end jobs:
1. Those who build components from scratch, or at least actively maintaining components
2a. Those to use only pre-built in-house components
2b. Those to use only pre-built external or opensource components
3. Mix of (1) and (2).
For my last company, we have 10% of front-end jobs are type 1 (a dedicated team in HQ), 90% are type 2a (every other front-end dev in the org), there's no type 2b or type 3 role in the company. Advantage: easier to achieve consistency. Disadvantage: occasional bottleneck.
*
If they can't write their own component, they're not a dev.. doh.gif

This post has been edited by silverhawk: Apr 3 2022, 03:14 PM
Find The Way
post Apr 3 2022, 09:13 PM

Enthusiast
*****
Senior Member
724 posts

Joined: Nov 2004


QUOTE(silverhawk @ Apr 3 2022, 03:13 PM)
If they can't write their own component, they're not a dev.. doh.gif
*
Indeed, job title ambiguity is an annoying thing, which is not uncommon in software development world bangwall.gif I experienced the pain

This post has been edited by Find The Way: Apr 3 2022, 09:22 PM
dstl1128
post Apr 6 2022, 02:50 PM

Look at all my stars!!
*******
Senior Member
4,463 posts

Joined: Jan 2003
QUOTE(kingkingyyk @ Aug 27 2021, 08:24 PM)
Obscenely short Python :
CODE
def solution(n: int):
   ans = [' '.join([str(y) for y in range(1,n+2-x)]) for x in range(1,n+1)]
   print('\n'.join(ans))

solution(4)


or maybe nicer.

CODE
def solution(n: int):
   full = [str(x) for x in list(range(1,n+2))]
   for i in range(1,n+1):
       print(' '.join(full[:-i]))

solution(4)


sweat.gif The truth is there are too many incompetent developers here.
*
Why so inefficient?
CODE

def fn(n):
   for x in range(n,0,-1):
       print('*'*x)

dexeric
post Apr 6 2022, 03:36 PM

Getting Started
**
Junior Member
82 posts

Joined: Oct 2008


CODE


#N = 4

For #J = #N downto 1
$Out = ''
  For #I = #J downto 1
     $Out =  conv(#I) + ' ' + $Out
  Endfor
Umsg($Out,-1)
Endfor



Niche language, [PROIV]

This post has been edited by dexeric: Apr 6 2022, 03:39 PM
dexeric
post Apr 6 2022, 03:44 PM

Getting Started
**
Junior Member
82 posts

Joined: Oct 2008


Not sure how the backend and frontend is differentiate as i am using niche language where frontend is interactive and backend is group by cycle.
I do notice alot dev do not know / scared to use loop. Not just recurrant loop, just while or for loop they also avoid...

It is just a shame for them to forgo such powerful syntax...
kingkingyyk
post Apr 6 2022, 10:20 PM

10k Club
Group Icon
Elite
15,391 posts

Joined: Mar 2008
QUOTE(dstl1128 @ Apr 6 2022, 02:50 PM)
Why so inefficient?
CODE

def fn(n):
   for x in range(n,0,-1):
       print('*'*x)

*
Compare the output of your code with mine.

QUOTE(dexeric @ Apr 6 2022, 03:44 PM)
I do notice alot dev do not know / scared to use loop. Not just recurrant loop, just while or for loop they also avoid...
*
Are they dev or just code technician? laugh.gif

This post has been edited by kingkingyyk: Apr 6 2022, 10:22 PM
dexeric
post Apr 7 2022, 08:59 AM

Getting Started
**
Junior Member
82 posts

Joined: Oct 2008


QUOTE(kingkingyyk @ Apr 6 2022, 10:20 PM)
Compare the output of your code with mine.
Are they dev or just code technician?  laugh.gif
*
I don't know... maybe stack overflow has big influence.. lol
SpiderMon68
post Apr 7 2022, 09:50 AM

Getting Started
**
Junior Member
69 posts

Joined: Oct 2017
QUOTE(FlierMate @ Aug 26 2021, 09:35 PM)
It took me (as an old-timer) awhile to solve it. Initially I thought single loop was enough, but double loops are necessary. (See https://dotnetfiddle.net/6D78Dv, TQ for the exercise :=)

Maybe this question is too mind-boggling for frontend developers?  rclxub.gif    By all means, I am not qualified for web frontend tech stack either.
*
Same here, been a while since I did any programming and was a great mind puzzle to solve. After penning on paper i downloaded a lightweight C/C++ compiler on my mac to try it out for fun.

Thanks TS for nice morning puzzle. I'm also not qualified for any 'end or any 'stack, just having fun.
SUSkykylala
post Apr 8 2022, 04:50 PM

New Member
*
Junior Member
25 posts

Joined: Feb 2014



Hey, if you guys like this kind of puzzle Leetcode has a lot of them. You can access a lot of the questions with just free account.
FlierMate
post Apr 8 2022, 08:11 PM

On my way
****
Validating
515 posts

Joined: Nov 2020
QUOTE(kykylala @ Apr 8 2022, 04:50 PM)
Hey, if you guys like this kind of puzzle Leetcode has a lot of them. You can access a lot of the questions with just free account.
*
Post #35 had mentioned about it anyway.


SUSkykylala
post Apr 8 2022, 09:55 PM

New Member
*
Junior Member
25 posts

Joined: Feb 2014



Oh, my bad. Didn't see that post.


QUOTE(dexeric @ Apr 6 2022, 03:44 PM)
Not sure how the backend and frontend is differentiate as i am using niche language where frontend is interactive and backend is group by cycle.
I do notice alot dev do not know / scared to use loop. Not just recurrant loop, just while or for loop they also avoid...

It is just a shame for them to forgo such powerful syntax...
*
Scared to use loop? How do they work then? Then they'll probably avoid recursion like the plague.

TS, I found this interview guide, how does it apply to the current market?
fronted guide
dexeric
post Apr 9 2022, 10:08 AM

Getting Started
**
Junior Member
82 posts

Joined: Oct 2008


QUOTE(kykylala @ Apr 8 2022, 09:55 PM)
Oh, my bad. Didn't see that post.
Scared to use loop? How do they work then? Then they'll probably avoid recursion like the plague.

TS, I found this interview guide, how does it apply to the current market?
fronted guide
*
Yes they do avoid like a plague... especially new generation
TSsilverhawk
post Apr 9 2022, 11:05 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(kykylala @ Apr 8 2022, 09:55 PM)
Oh, my bad. Didn't see that post.
Scared to use loop? How do they work then? Then they'll probably avoid recursion like the plague.

TS, I found this interview guide, how does it apply to the current market?
fronted guide
*
Most of the candidates I interviewed would have failed that guide as well.

I generally don't like asking questions which you can google to get the job done. After all, I don't expect people to remember all the CSS rules by heart or how the different flexbox arguments work together to build a layout.

What I look for is fundamental understanding that powers your decision making. For example, do they understand javascript's callbacks and async nature? do they understand what a virtualdom is, or why we have state management. These things affect how you write code and even what sort of questions you google to solve, and if you lack understanding you will end up googling the wrong things.
twigky
post Apr 12 2022, 08:13 AM

Getting Started
**
Junior Member
59 posts

Joined: Jun 2009


While reading this post, feel it's could go really bad if an interview conducted by a pure manager without tech background. And it didn't get any better if conduct by a tech person interview without leadership skill.

Perhaps panel interview really the way to go.
15cm
post Apr 12 2022, 08:27 PM

Getting Started
**
Junior Member
178 posts

Joined: Apr 2022

i asked some of my friends this question, around 4/10 of them cant answer as well, not as much as 90% la...

but they also quite defensive, they think this is leetcode tricks, not relevant to front end..
TSsilverhawk
post Apr 12 2022, 08:47 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(15cm @ Apr 12 2022, 08:27 PM)
i asked some of my friends this question, around 4/10 of them cant answer as well, not as much as 90% la...

but they also quite defensive, they think this is leetcode tricks, not relevant to front end..
*
So ask them if they had a json like this

» Click to show Spoiler - click again to hide... «


and they had to display that data as a table, how would they do it? Assume that the columns are selectable by the user, so the result is dynamic
nyem
post Jul 7 2022, 10:03 PM

Enthusiast
*****
Senior Member
746 posts

Joined: Jan 2007


QUOTE(silverhawk @ Apr 12 2022, 08:47 PM)
So ask them if they had a json like this

» Click to show Spoiler - click again to hide... «


and they had to display that data as a table, how would they do it? Assume that the columns are selectable by the user, so the result is dynamic
*
Not sure what you mean by dynamic, but here's my version of a table with selectable and sortable columns

Came across this javascript interview questions and I fail every single one of them bangwall.gif


Buffalo Soldier
post Jul 7 2022, 10:16 PM

Casual
***
Junior Member
409 posts

Joined: Aug 2005

Kinda verbose, but here's my Python answer...
CODE
def reverse_print(target):
   for outer in range(target + 1, 0, -1):
       for inner in range(1, outer):
           print(inner, end="")
       print()

reverse_print(4)

TSsilverhawk
post Jul 7 2022, 10:44 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(nyem @ Jul 7 2022, 10:03 PM)
Not sure what you mean by dynamic, but here's my version of a table with selectable and sortable columns

Came across this javascript interview questions and I fail every single one of them  bangwall.gif
*
dynamic meaning the data changes, so you're really creating a reusable component that automatically creates the headers.

Try loading this endpoint: https://sandbox.darylphuah.com/invq1/data.php

Each time you load the endpoint, it should return you a randomly chosen dataset. Your component should be able to render them all. There are a few little tricks in some datasets.
FlierMate1
post Jul 7 2022, 11:29 PM

Getting Started
**
Validating
139 posts

Joined: Jun 2022
QUOTE(silverhawk @ Jul 7 2022, 10:44 PM)
"darylphuah".... OMG, now I understand you better. tongue.gif

nyem
post Jul 8 2022, 12:04 AM

Enthusiast
*****
Senior Member
746 posts

Joined: Jan 2007


QUOTE(silverhawk @ Jul 7 2022, 10:44 PM)
dynamic meaning the data changes, so you're really creating a reusable component that automatically creates the headers.

Try loading this endpoint: https://sandbox.darylphuah.com/invq1/data.php

Each time you load the endpoint, it should return you a randomly chosen dataset. Your component should be able to render them all. There are a few little tricks in some datasets.
*
CORS prevented access to that endpoint. Otherwise can test from https://bl.ocks.org/nyem69/29896289104af5b5a5e27a61041756a9


CORS proxy : https://bl.ocks.org/nyem69/c674d91ac78ea44723bf6ad26fc3fb6c

This post has been edited by nyem: Jul 8 2022, 03:39 AM
TSsilverhawk
post Jul 8 2022, 12:15 AM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(FlierMate1 @ Jul 7 2022, 11:29 PM)
"darylphuah".... OMG, now I understand you better.  tongue.gif
*
laugh.gif
15cm
post Jul 8 2022, 07:08 PM

Getting Started
**
Junior Member
178 posts

Joined: Apr 2022

QUOTE(FlierMate1 @ Jul 7 2022, 11:29 PM)
"darylphuah".... OMG, now I understand you better.  tongue.gif
*
user posted image *googles furiously*
TSsilverhawk
post Jul 8 2022, 07:16 PM

I'm Positively Lustrous
Group Icon
Elite
4,534 posts

Joined: Jan 2003


QUOTE(15cm @ Jul 8 2022, 07:08 PM)
user posted image *googles furiously*
*
laugh.gif My identity is quite public actually
FlierMate1
post Jul 8 2022, 07:30 PM

Getting Started
**
Validating
139 posts

Joined: Jun 2022
QUOTE(15cm @ Jul 8 2022, 07:08 PM)
user posted image *googles furiously*
*
QUOTE(silverhawk @ Jul 8 2022, 07:16 PM)
laugh.gif My identity is quite public actually
*
Haha. Can I say so, one of the best web developer partnered with the one of the best web designer.

This post has been edited by FlierMate1: Jul 9 2022, 12:00 AM
Fraus
post Nov 16 2022, 02:05 AM

New Member
*
Validating
15 posts

Joined: Nov 2022
Can I ask in behalf of TS? rclxs0.gif Another challenge, similar to original question posed by silverhawk, but this time print a tree (or triangle) with variable size.

https://pictr.com/images/2022/11/16/EadV9c.png

Of course, you can simply print each line, but what if now you must solve it using for...loop (with variable size input from user).
angch
post Nov 16 2022, 11:54 AM

On my way
****
Junior Member
559 posts

Joined: Jul 2006
CODE
% echo 10 | perl -e'$_=<>;--$_;print $_=" "x$_."*"." "x$_."\n";print$_ while(s/ \*/\*\*/g&&s/\* /\*\*/g);'
        *
       ***
      *****
     *******
    *********
   ***********
  *************
 ***************
*****************
*******************

user posted image

No for loop, failed. It's just a 1D cellular automata.

This post has been edited by angch: Nov 16 2022, 12:01 PM
Fraus
post Nov 16 2022, 03:06 PM

New Member
*
Validating
15 posts

Joined: Nov 2022
QUOTE(angch @ Nov 16 2022, 11:54 AM)

CODE
% echo 10 | perl -e'$_=<>;--$_;print $_=" "x$_."*"." "x$_." ";print$_ while(s/ */**/g&&s/* /**/g);'

        *

       ***

      *****

     *******

    *********

   ***********

  *************

 ***************

*****************

*******************


https://pictr.com/images/2022/11/16/Eawj7v.md.png

No for loop, failed. It's just a 1D cellular automata.
*



"Automata" is a branch of mathematical systems theory, from Wikipedia:
QUOTE
Automata play a major role in the theory of computation, compiler construction, artificial intelligence, parsing and formal verification.


Although I do not understand perl script, but I am amazed at how you code them.

Output in my Linux terminal:
user posted image

Thanks for the inspiring solution.
iammyself
post Nov 16 2022, 06:29 PM

Getting Started
**
Junior Member
225 posts

Joined: May 2011
QUOTE(Fraus @ Nov 16 2022, 02:05 AM)
Can I ask in behalf of TS?   rclxs0.gif   Another challenge, similar to original question posed by silverhawk, but this time print a tree (or triangle) with variable size.
<a href='https://pictr.com/images/2022/11/16/EadV9c.png' target='_blank'>https://pictr.com/images/2022/11/16/EadV9c.png </a>
Of course, you can simply print each line, but what if now you must solve it using for...loop (with variable size input from user).
*
Here's my solution in Go.

CODE


package main

import (
   "fmt"
   "strings"
)

func main() {
   fmt.Println("5")
   printStarTree(5)
   fmt.Println("10")
   printStarTree(10)
}

func printStarTree(n int) {
   // Calculate the max number of padded spaces on the left
   spaceCount := (n - 1)/ 2
   var padBuilder strings. Builder
   for j := 0; j < spaceCount; j++ {
       padBuilder.WriteRune(' ')
   }
   padding := padBuilder.String()

   // This string builder is used to accumulate the stars
   var starBuilder strings. Builder
   starBuilder.WriteRune('*')

   // In each iteration, the padding contracts and the stars expand
   for i := 1; i <= n; i += 2 {
       // Print padding + stars
       fmt.Println(padding[:spaceCount] + starBuilder.String())

       // Stars increase at the rate of two per row
       starBuilder.WriteString("**")

       // Reduce padding for the next row
       spaceCount--
   }
}



Output

user posted image

This post has been edited by iammyself: Nov 16 2022, 06:31 PM
Fraus
post Nov 16 2022, 08:23 PM

New Member
*
Validating
15 posts

Joined: Nov 2022
QUOTE(iammyself @ Nov 16 2022, 06:29 PM)

Here's my solution in Go.

» Click to show Spoiler - click again to hide... «


Output

https://pictr.com/images/2022/11/16/Eaf8Gr.jpg
*



Thanks for your unique solution! It is an interesting way to print the tree by counting the stars per row, which is always an odd number.

From my testing, both gives identical result:
CODE


printStarTree(9)

printStarTree(10)



Thumbs up for your solution! thumbsup.gif


angch
post Nov 16 2022, 09:36 PM

On my way
****
Junior Member
559 posts

Joined: Jul 2006
And here's my solution in Go. wink.gif
https://go.dev/play/p/GiBSWFJpAfg

CODE
package main

import (
"fmt"
"strings"
)

func stars(i int) {
// minimize the allocs!
for buf := []byte(strings.Repeat(" ", i*2+1)); i > 0; i-- {
 buf[i] = '*'
 buf[len(buf)-i-1] = '*'
 fmt.Println(string(buf))
}
}

func main() {
stars(3)
stars(5)
stars(10)
}


Not quite the same as the Perl version, but the gist is the same: construct the first line of N spaces, one star, and N spaces. And keep repeating printing out each line, adding two stars per iteration, until we can't add any more.

The Perl version basically searches and replaces (space, star) with (star, star) and (star, space) with (star, star) every loop until it can't find any (space, star).

This post has been edited by angch: Nov 16 2022, 09:43 PM
iammyself
post Nov 16 2022, 10:14 PM

Getting Started
**
Junior Member
225 posts

Joined: May 2011
QUOTE(angch @ Nov 16 2022, 09:36 PM)
And here's my solution in Go. wink.gif
https://go.dev/play/p/GiBSWFJpAfg

CODE
package main

import (
"fmt"
"strings"
)

func stars(i int) {
// minimize the allocs!
for buf := []byte(strings.Repeat(" ", i*2+1)); i > 0; i-- {
 buf[i] = '*'
 buf[len(buf)-i-1] = '*'
 fmt.Println(string(buf))
}
}

func main() {
stars(3)
stars(5)
stars(10)
}


Not quite the same as the Perl version, but the gist is the same: construct the first line of N spaces, one star, and N spaces. And keep repeating printing out each line, adding two stars per iteration, until we can't add any more.

The Perl version basically searches and replaces (space, star) with (star, star) and (star, space) with (star, star) every loop until it can't find any (space, star).
*
Oh, I like your approach -- start with spaces and just fill in the stars. Nice work.
angch
post Nov 17 2022, 12:52 PM

On my way
****
Junior Member
559 posts

Joined: Jul 2006
Bonus. Sierpinski's, using same method (Cellular Automata)

user posted image

https://go.dev/play/p/JZ5JVjIfMcD

https://gist.github.com/angch/831801a7660da...69e8bcd0bb369f6

Meh, LYN doesn't like me posting code for some reason.

CODE
package main

import (
"fmt"
"strings"
)

func cell(cells []byte, rule int) {
t := [8]byte{}
for i := 0; i < 8; i++ {
 switch rule & 1 {
 case 0:
  t[i] = ' '
 case 1:
  t[i] = 'X'
 }
 rule >>= 1
}
for row := 0; row < 100; row++ {
 fmt.Println(string(cells))
 state := 0
 if cells[0] == 'X' {
  state = 1
 }
 for i := 1; i < len(cells); i++ {
  state = (state << 1) & 7
  if cells[i] == 'X' {
   state = state | 1
  }
  cells[i-1] = t[state]
 }
 state = (state << 1) & 7
 cells[len(cells)-1] = t[state]
}
}

func main() {
buf := []byte(strings.Repeat(" ", 120))

// single X in the middle
buf[len(buf)/2] = 'X'
cell(buf, 18) // 18 = 00010010 binary
}


This post has been edited by angch: Nov 17 2022, 12:53 PM
yunuskk P
post Nov 17 2022, 03:53 PM

New Member
*
Probation
1 posts

Joined: Oct 2021
CODE
#include <stdio.h>

int main(void)
{
int rows = 0;
int i = 0;
int j = 0;
int Numspace = 0;
int Numstar = 0;
int Maxstar = 0;

printf("Number of Rows : ");
scanf("%d", &rows);

Maxstar = 2*rows - 1;
for(i = 0; i < rows; i++)
{
 Numstar = 2*i + 1;
 Numspace = (Maxstar - Numstar)/2;
   
 if (Numspace > 0)
  printf("%*c", Numspace, ' ');
 for(j = 0; j < Numstar; j++)
  printf("*");
 printf("\n");

}

return 0;


Using c
Fraus
post Nov 17 2022, 05:39 PM

New Member
*
Validating
15 posts

Joined: Nov 2022
QUOTE(angch @ Nov 17 2022, 12:52 PM)

Bonus. Sierpinski's, using same method (Cellular Automata)

Meh, LYN doesn't like me posting code for some reason.

*



Amazing, rclxms.gif this is beyond my comprehension. I notice you use binary string and bitwise operation.

QUOTE(yunuskk @ Nov 17 2022, 03:53 PM)

Using c
*



Thank you for coming up with a C program, your solution is similar to mine, particularly the part to print stars.

user posted image

thumbsup.gif
iammyself
post Nov 17 2022, 07:52 PM

Getting Started
**
Junior Member
225 posts

Joined: May 2011
QUOTE(Fraus @ Nov 16 2022, 08:23 PM)
Thanks for your unique solution! It is an interesting way to print the tree by counting the stars per row, which is always an odd number.
From my testing, both gives identical result:
CODE


printStarTree(9)

printStarTree(10)


Thumbs up for your solution!  thumbsup.gif
*
Oh... I just realized that the input is the number of rows / height of the tree.
For some reason I was assuming that the input is the width of the tree.

This post has been edited by iammyself: Nov 17 2022, 07:57 PM
iammyself
post Nov 17 2022, 08:22 PM

Getting Started
**
Junior Member
225 posts

Joined: May 2011
QUOTE(iammyself @ Nov 16 2022, 06:29 PM)
Here's my solution in Go.

Output

user posted image
*
I couldn't edit my original post. But I've updated my original solution to support height as the input.
I really like other forumers solutions and I think they work a little better than my solution, but just for completeness:-

CODE


package main

import (
   "fmt"
   "strings"
)

func main() {
   fmt.Println("Width: 5")
   printStarTreeWidth(5)
   fmt.Println("Width: 10")
   printStarTreeWidth(10)

   fmt.Println("Height: 3")
   printStarTreeHeight(3)
   fmt.Println("Height: 5")
   printStarTreeHeight(5)
}

func printStarTreeHeight(h int) {
   printStarTreeWidth((2 * h) - 1)
}

func printStarTreeWidth(w int) {
   // Calculate the max number of padded spaces on the left
   spaceCount := (w - 1)/ 2
   padding := strings.Repeat(" ", spaceCount)

   // This string builder is used to accumulate the stars
   var starBuilder strings.Builder
   starBuilder.WriteRune('*')

   // In each iteration, the padding contracts and the stars expand
   for i := 1; i <= w; i += 2 {
       // Print padding + stars
       fmt.Println(padding[:spaceCount] + starBuilder.String())

       // Stars increase at the rate of two per row
       starBuilder.WriteString("**")

       // Reduce padding for the next row
       spaceCount--
   }
}



This post has been edited by iammyself: Nov 17 2022, 08:23 PM
Fraus
post Nov 17 2022, 08:57 PM

New Member
*
Validating
15 posts

Joined: Nov 2022
QUOTE(iammyself @ Nov 17 2022, 08:22 PM)
I couldn't edit my original post. But I've updated my original solution to support height as the input.
I really like other forumers solutions and I think they work a little better than my solution, but just for completeness:-

» Click to show Spoiler - click again to hide... «

*
That's very clever of you for the quick fix. thumbup.gif

(My bad for not defining properly the "variable size" in my question, it is not wrong either to do it by width of the tree.)


iammyself
post Nov 17 2022, 09:40 PM

Getting Started
**
Junior Member
225 posts

Joined: May 2011
QUOTE(Fraus @ Nov 17 2022, 08:57 PM)
That's very clever of you for the quick fix.  thumbup.gif

(My bad for not defining properly the "variable size" in my question, it is not wrong either to do it by width of the tree.)
*
Nah, I should have clarified. Anyway, thanks for posting the question.
FlierMate
post Nov 20 2022, 02:39 PM

On my way
****
Validating
515 posts

Joined: Nov 2020
If any of you want another challenge, can try print the diamond programmatically.

user posted image
FlierMate
post Nov 20 2022, 02:41 PM

On my way
****
Validating
515 posts

Joined: Nov 2020
My solution for the star tree, in C#:

CODE
using System;
                                       
public class Program
{
       public static void Main()
       {
               int size=6;
               for (int a=0; a<=size; a++)
               {
                       for (int b=size; b>a; b--)
                               Console.Write(" ");
                       
                       for (int c=1; c<a*2; c++)
                               Console.Write("*");
                       
                       for (int b=size; b>a; b--)
                               Console.Write(" ");
                       
                       Console.WriteLine();
               }
       }
}

angch
post Nov 20 2022, 08:03 PM

On my way
****
Junior Member
559 posts

Joined: Jul 2006
QUOTE(FlierMate @ Nov 20 2022, 02:39 PM)
If any of you want another challenge, can try print the diamond programmatically.

user posted image
*
"Challenge", tongue.gif C'mon, make it a real challenge.
iammyself
post Nov 21 2022, 01:16 PM

Getting Started
**
Junior Member
225 posts

Joined: May 2011
QUOTE(FlierMate @ Nov 20 2022, 02:39 PM)
If any of you want another challenge, can try print the diamond programmatically.

user posted image
*
I'll play! But before we begin... what's the input parameter? icon_idea.gif
FlierMate
post Nov 21 2022, 02:10 PM

On my way
****
Validating
515 posts

Joined: Nov 2020
QUOTE(iammyself @ Nov 21 2022, 01:16 PM)
I'll play! But before we begin... what's the input parameter?  icon_idea.gif
*
Honestly I don't know the standard input parameter. Personally I use the upper half as the size (from middle to top), which is easier when coding.

Thank you for willing to play. smile.gif

This post has been edited by FlierMate: Nov 21 2022, 02:10 PM
angch
post Nov 21 2022, 04:22 PM

On my way
****
Junior Member
559 posts

Joined: Jul 2006
user posted image

Alright, Mr Assembly, take this!

150 bytes. DOS 16bit .EXE

It grabs the number of diamonds from the command line.

user posted image

https://gist.github.com/angch/d82694d44c7af...787d944034ff719
FlierMate
post Nov 21 2022, 04:44 PM

On my way
****
Validating
515 posts

Joined: Nov 2020
QUOTE(angch @ Nov 21 2022, 04:22 PM)
user posted image

Alright, Mr Assembly, take this!

150 bytes. DOS 16bit .EXE

It grabs the number of diamonds from the command line.

user posted image

https://gist.github.com/angch/d82694d44c7af...787d944034ff719
*
Very nice! I am aware that you know low-level stuff, but I didn't know you can code in Assembly (i8086)! Fantastic!

I didn't look up interrupt list, how did you get command line argument in DOS? Through "di" register? I know in Windows (through API) and Linux (through stack), but don't know about DOS.

150 bytes is not the smallest, biggrin.gif Because it wrap it with MZ header.
I think you already knew, you can produce .COM in FASM by changing the first line to:
CODE
org 100h    


Now it is 118 bytes! Yeah.

I notice the largest size is 12 (turn to 25 rows), because you understand that the DOS terminal window is only 25 rows. It shows you pay attention to detail.

Again, nice one! (Mine is in C#, I am reluctant to do any algorithmic coding using Assembly)
angch
post Nov 21 2022, 05:48 PM

On my way
****
Junior Member
559 posts

Joined: Jul 2006
QUOTE(FlierMate @ Nov 21 2022, 04:44 PM)
Very nice! I am aware that you know low-level stuff, but I didn't know you can code in Assembly (i8086)! Fantastic!

I didn't look up interrupt list, how did you get command line argument in DOS? Through "di" register? I know in Windows (through API) and Linux (through stack), but don't know about DOS.

150 bytes is not the smallest,  biggrin.gif   Because it wrap it with MZ header.
I think you already knew, you can produce .COM in FASM by changing the first line to:
CODE
org 100h    


Now it is 118 bytes! Yeah.

I notice the largest size is 12 (turn to 25 rows), because you understand that the DOS terminal window is only 25 rows. It shows you pay attention to detail.

Again, nice one! (Mine is in C#, I am reluctant to do any algorithmic coding using Assembly)
*
I wasn't used to FASM. Was a TASM/MASM dude. Had to relearn a lot of things. Plenty of things I can do to optimize it further, but it was just a quick hack.

There was a few magic memory locations you'd need to know for asm in DOS: CS:80h is the len of the args, CS:81h onwards is the command line argument. 255 (Edit: 20h, not 100h) max chars, of course. 0B800h is the text mode buffer, etc.

This post has been edited by angch: Nov 21 2022, 07:59 PM
iammyself
post Nov 21 2022, 09:24 PM

Getting Started
**
Junior Member
225 posts

Joined: May 2011
QUOTE(FlierMate @ Nov 20 2022, 02:39 PM)
If any of you want another challenge, can try print the diamond programmatically.

user posted image
*
Here's my submission in Go! The code supports both height and width as the input.

I can't seem to get the formatting to work below. But you can see the code in action here: https://go.dev/play/p/tuerhNZt2wr

CODE

// ASCII codes for asterisk and space
const (
star  = 42
space = 32
)

func printDiamondH(h int) {
if h%2 == 0 {
 printDiamondW(h + 1)
} else {
 printDiamondW(h)
}
}
func printDiamondW(w int) {
row := make([]byte, w)
for i, _ := range row {
 row[i] = space
}

// Starting positions for the star(s)
l, r := w/2, w/2
if w%2 == 0 {
 l = r - 1
} // When the width is even, the first and last row will have 2 stars instead of 1

// Grow downward until the middle row
for l >= 0 && r < len(row) {
 row[l], row[r] = star, star

 fmt.Println(string(row))

 row[l], row[r] = space, space // reset the array

 l--
 r++
}

// Manually move the pointers so the middle row isn't printed twice
l = 1
r = len(row) - 2

// Shrink it back
for l <= r {
 row[l], row[r] = star, star

 fmt.Println(string(row))

 row[l], row[r] = space, space // reset the array

 l++
 r--
}
}


Output:

user posted image

This post has been edited by iammyself: Nov 21 2022, 09:28 PM
FlierMate
post Nov 21 2022, 10:11 PM

On my way
****
Validating
515 posts

Joined: Nov 2020
QUOTE(iammyself @ Nov 21 2022, 09:24 PM)
Here's my submission in Go! The code supports both height and width as the input.

I can't seem to get the formatting to work below. But you can see the code in action here: https://go.dev/play/p/tuerhNZt2wr

» Click to show Spoiler - click again to hide... «

Output:

user posted image
*
Thank you for the code, thumbsup.gif looks simpler but working.

Now I think I slowly understand Go:
CODE
for l >= 0 && r < len(row) { ......

for l <= r {.....

....is actually a WHILE...LOOP, not FOR...NEXT.

I like the way you reposition the star at both end with "l--" & "r++" or "r--" and "l++".

Unlike my solution, you print one line at a time, which is neater.


FlierMate
post Nov 21 2022, 10:15 PM

On my way
****
Validating
515 posts

Joined: Nov 2020
I hope @silverhawk wouldn't mind for further discussion about my coding challenge.

I will start new topic for coding challenge (if any) in the future.
Sorry for hijacking your thread.