Welcome Guest ( Log In | Register )

9 Pages « < 6 7 8 9 >Bottom

Outline · [ Standard ] · Linear+

 Frontend Developers, what's happening?

views
     
TSsilverhawk
post Jul 7 2022, 10:44 PM

I'm Positively Lustrous
Group Icon
Elite
4,537 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,537 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,537 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
560 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
560 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
560 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.)



9 Pages « < 6 7 8 9 >Top
 

Change to:
| Lo-Fi Version
0.0237sec    0.18    5 queries    GZIP Disabled
Time is now: 4th February 2023 - 09:45 AM