Skip to content

Instantly share code, notes, and snippets.

@arif98741
Created March 21, 2024 18:19
Show Gist options
  • Save arif98741/7d2fbd02c0438d92ae8d5d549214a370 to your computer and use it in GitHub Desktop.
Save arif98741/7d2fbd02c0438d92ae8d5d549214a370 to your computer and use it in GitHub Desktop.
Print Combination using Javascript using two dimentional array
let colorsSizes = [["Red","Blue","Black"],["M","L","XL"]];
for (let i = 0; i < colorsSizes[0].length; i++) {
for (let j = 0; j < colorsSizes[1].length; j++) {
console.log(colorsSizes[0][i] + " - " + colorsSizes[1][j]);
}
}
Red - M
Red - L
Red - XL
Blue - M
Blue - L
Blue - XL
Black - M
Black - L
Black - XL
const colorsSizes = [["Red","Blue","Black"],["M","L","XL"], [10, 12, 14]];
for (let i = 0; i < colorsSizes[0].length; i++) {
for (let j = 0; j < colorsSizes[1].length; j++) {
for (let k = 0; k < colorsSizes[2].length; k++) {
console.log(colorsSizes[0][i] + "-" + colorsSizes[1][j] + "-" + colorsSizes[2][k]);
}
}
}
Red-M-10
Red-M-12
Red-M-14
Red-L-10
Red-L-12
Red-L-14
Red-XL-10
Red-XL-12
Red-XL-14
Blue-M-10
Blue-M-12
Blue-M-14
Blue-L-10
Blue-L-12
Blue-L-14
Blue-XL-10
Blue-XL-12
Blue-XL-14
Black-M-10
Black-M-12
Black-M-14
Black-L-10
Black-L-12
Black-L-14
Black-XL-10
Black-XL-12
Black-XL-14
const combinations = [["Red","Blue","Black"],["M","L","XL"], [10, 12, 14],["Dhaka", "Chittagong","Rajshahi","Tangail"]];
for (let color of combinations[0]) {
for (let size of combinations[1]) {
for (let number of combinations[2]) {
for (let city of combinations[3]) {
console.log(color + "-" + size + "-" + number + "-" + city);
}
}
}
}
Red-M-10-Dhaka
Red-M-10-Chittagong
Red-M-10-Rajshahi
Red-M-10-Tangail
Red-M-12-Dhaka
Red-M-12-Chittagong
Red-M-12-Rajshahi
Red-M-12-Tangail
Red-M-14-Dhaka
Red-M-14-Chittagong
Red-M-14-Rajshahi
Red-M-14-Tangail
Red-L-10-Dhaka
Red-L-10-Chittagong
Red-L-10-Rajshahi
Red-L-10-Tangail
Red-L-12-Dhaka
Red-L-12-Chittagong
Red-L-12-Rajshahi
Red-L-12-Tangail
Red-L-14-Dhaka
Red-L-14-Chittagong
Red-L-14-Rajshahi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment