0% found this document useful (0 votes)
36 views3 pages

Star Pattern

The document contains various JavaScript code snippets for generating patterns using loops. It includes examples of creating pyramids with asterisks and numbers, as well as a function that applies a transformation to an array. The code demonstrates different techniques for formatting output in the console.

Uploaded by

kamalkhokher804
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

Star Pattern

The document contains various JavaScript code snippets for generating patterns using loops. It includes examples of creating pyramids with asterisks and numbers, as well as a function that applies a transformation to an array. The code demonstrates different techniques for formatting output in the console.

Uploaded by

kamalkhokher804
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Start pattern

// let L = 5

// for(let i = 0; i<L; i++) {


// for (let j = 0; j<L-i-1; j++) {
// process.stdout.write(" ")
// }
// for(let j = 0; j<2*i+1; j++) {
// process.stdout.write("*")
// }
// console.log(" ")

// }

// let L = 5
// let space =parseInt( L + (L/2 + (L/2-2)));
// for(let i = 0; i<L; i++) {
// for(j=0; j<space; j++) {
// process.stdout.write(" ");
// }
// for(j = 0; j<=i*2; j++) {
// process.stdout.write(`${j+1}`)
// }
// space-=2;
// console.log()

// }

function kamal(arr , func2) {


let arr2 = [];
for(let i =0; i<arr.length; i++) {
const a = func2(arr[i] , i);
arr2.push(a);
}
return arr2;
}

function func2 (num ,index){


return num
}
const arr = [1 , 2 , 3, 4];

console.log(kamal(arr , func2));

123456789
1234567
12345
123
1

let N = 19
digit = N+N-1;
for(let i=0; i<N; i++) {
for(j=0; j<digit; j++) {
process.stdout.write(`${j+1}`)
}
digit -= 2
console.log("")
}

// let N = 5;

// // Loop for the top half of the pattern


// for (let i = 0; i < N; i++) {
// // Print leading asterisks
// process.stdout.write(' '.repeat(N - i - 1));

// // Print numbers in the sequence


// for (let j = 1; j <= 2 * i + 1; j++) {
// process.stdout.write(`${j}`);
// }

// // Move to the next line


// console.log();
// }

// // Loop for the bottom half of the pattern


// for (let i = N - 2; i >= 0; i--) {
// // Print leading asterisks
// process.stdout.write(' '.repeat(N - i - 1));

// // Print numbers in the sequence


// for (let j = 1; j <= 2 * i + 1; j++) {
// process.stdout.write(`${j}`);
// }

// // Move to the next line


// console.log();
// }

let n = 6
let i , j , k;

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


for (j = i; j < n; j++) {
process.stdout.write(` `); }

for (k = 1; k <= (2 * i - 1); k++) {


// printing stars.
if (k == 1 || i == n || k == (2 * i - 1)) {
process.stdout.write(`*`);
} else
process.stdout.write(` `);
}
console.log()
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy