Angular2 how to display an array of numbers [closed] - html

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Whats is the most elegant solution in angular2 for displaying an html table of z numbers in x rows and y columns?
X, Y and Z are numbers not necessarily collections. Also the table should contain numbers 1 to z.

I would do it like this : Plunker
Component
rows : any[];
cols : any[];
constructor() {
this.rows = Array(50).fill('');
this.cols = Array(10).fill('');
}
Template :
<table>
<tr *ngFor="let row of rows; let rowId = index">
<td *ngFor="let col of cols; let colId = index">{{rowId + colId*10+1}}</td>
</tr>
</table>

Related

How to put an object's property to a href in AJAX? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a small question. How to put an object's property to href.
I marked with comment the line
success: function (listOfTags) {
let tagData = '';
$.each(listOfTags, function (i, tag) {
// ON THE NEXT LINE
tagData += '' + tag.name + '</li>';
});
$('#recentTags').html(tagData);
}
Try this:
tagData += `<li class="post-tag">${tag.name}</li>`;
For a valid markup, the anchor should be inside the list item, and the latter should be the child of a ul like this:
//before the loop
tagData += '<ul>';
tagData += `<li class="post-tag">${tag.name}</li>`;
//after the loop
tagData += '</ul>';

Why is the result of (a+b+c')(a'b'+c) not 1? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
So I got his problem as homework in my course, when I solved it the result I came up with was 1, but everywhere I check the solution stops at line 4 is if it is the final solution, but I can't spot the error in my logic for some reason!
Line1: (a+b+c')(a'b'+c)
Line2: =aa'b'+ba'b'+c'a'b'+ac+bc+c'c
Line3: =0+0+c'a'b'+ac+bc+0
Line4: =c'a'b'+ac+bc
Line5: =c'a'b'+c(a+b)
Line6: =c'+c(a'b'+(a+b))
Line7: =1*(a'b'+(a+b))
Line8: =1
You can do a very little bit better if XOR (^) is a primitive operation in your system:
Line1: (a+b+c')(a'b'+c)
Line2: = aa'b'+ba'b'+c'a'b'+ac+bc+c'c
Line3: = 0+0+c'a'b'+ac+bc+0
Line4: = c'a'b'+ac+bc
Line5: = c'a'b'+c(a+b)
Line6: = c'a'b'+c(a'b')'
Line7: = c^(a'b')
Your error is the following:
Line5: = c'a'b'+c(a+b)
Line6: = c'+c(a'b'+(a+b))
Clearly, lines 5 and 6 do not show equivalent expressions because c=0 satisfies the second regardless of a and b whereas c=0, a=1 does not satisfy the first.

Merge divs with same value from angular [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am trying to make a Calendar of my own
https://stackblitz.com/edit/angular-1kfbod?file=src/app/app.component.css
This is a full example of my component.
How can I merge the week divs that have the same value {{day.weekNumber}} (one div instead of 4 for the example below)?
In your case, you should have separate array for your week numbers.
Typescript
public weekNumbers: number[] = [];
public rowWidth: any = 100 + '%';
ngOnInit() {
...
... // your existing code
...
let weeks = [];
for (let i = 1; i <= this.numberOfDaysCurrentMonth; i++) {
this.daysToDisplayInCurrentMonth[i - 1] = new Date(this.currentYear, this.currentMonth - 1, i).getDay();
const day = {
number: i,
weekDay: new Date(this.currentYear, this.currentMonth - 1, i).getDay(),
name: this.dayNames[this.daysToDisplayInCurrentMonth[i - 1]],
weekNumber: this.getWeekNumber(new Date(this.currentYear, this.currentMonth - 1, i))
};
weeks.push(day.weekNumber);
this.days.push(day);
}
this.weekNumbers = [];
weeks.forEach((ele) => {
if(this.weekNumbers.indexOf(ele) < 0) {
this.weekNumbers.push(ele);
}
});
this.rowWidth = (100/this.weekNumbers.length) + '%';
}
HTML
<div class="row-calendar">
<div class="week-number" [style.width]="rowWidth" *ngFor="let week of weekNumbers">
<label class="number-label"><span>{{week}} </span></label>
</div>
</div>

calculate a boolean flag [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a very basic question related to boolean logic.
I have two boolean flags- flagA and flagB. I need to calculate flagC based on the values of flagA and flagB.
The code/rules are:
if($flagA && $flagB) {
$flagC = true;
} else if (!$flagA || !$flagB) {
$flagC = false;
} else if(!$flagA && !$flagB) {
$flagC = true;
}
These rules match with the XNOR truth table - http://en.wikipedia.org/wiki/XNOR_gate
I want to find out different ways to re-write the above code(if possible) with:
fewer lines of code
better performance (even if it is a minute difference)
using bit shifting?
The languages I am hoping to write this in - php, ruby/ruby on rails.
Any help/pointers will be great!
Thanks!
Don't use these languages much but this might work:
$flagC = ($flagA == $flagB);
From the link posted: http://en.wikipedia.org/wiki/XNOR_gate
two-input version implements logical equality, behaving according to the truth table to the right. A HIGH output (1) results if both of the inputs to the gate are the same. If one but not both inputs are HIGH (1), a LOW output (0) results.
So flagC is true when flagA equals flagB.
if($flagA && $flagB) {
$flagC = true;
} else {
$flagC = false;
}
(Your second rule covers all other cases.)

Can I use the function yes () to return 1 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is the following function is correct?
local function yes()
return 1
end
local function no()
return 0
end
Can I use it to set the values ​​of the variables in this way?
local May_I = yes()
if May_I ~= 0 then
-- Yes I can do that
end
I like numbers, but sometimes they are not very precise.
You can deal with the imprecision you mentioned like so:
> epsilon = 1e-2
> function yes()
>> return 1
>> end
> if math.abs( yes() - 1 ) <= epsilon then
>> print("Yes I can")
>> end
Yes I can
Or alternately, be precise and use true and false.