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 4 months ago.
Improve this question
[Trying to count from 1-10 using a for loop][1]
For our purposes here, pay attention to the second for loop in this picture.
[1]: https://i.stack.imgur.com/iUnGD.png
Use this code for print result in console:
public static void LoopSolution()
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine($"Count: {i + 1}");
}
}
In console result:
Related
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 1 year ago.
Improve this question
I'm looking a way to check string contains an uppercase. The following code:
word := "Hello"
for _,v := range word{
if .... {
fmt.Print("contain uppercase letter")
}
}
You have to check each rune:
hasUpper:=false
for _,r:=range word {
if unicode.IsUpper(r) {
hasUpper=true
break
}
}
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 2 years ago.
Improve this question
I want to write a script on Bash that does:
I have a file, that consists of string like this:
2002-02-15 00:01:19 217.21.43.21 RES company_name
2002-02-15 00:01:19 217.21.43.21 RES company_name
2002-02-15 00:01:19 217.21.43.21 DEL company_name
2002-02-13 00:01:19 217.21.43.21 RES company_name
I need to calculate the number of requests with parameter RES for each day.
Output of script should be:
2002-02-15 2
2002-02-13 1
This should be enough:
awk '/RES/ { N[$1] += 1; }; END { for (day in N) { print day, N[day] } }' your_input
It creates an associative array N whose indices are the days of the first field, and whose values are incremented by one for every line matching RES.
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 4 years ago.
Improve this question
My data is in the form of:
a = [
{
"a_id":101,
"a_value":100000.0,
"a_quantity":360.0
},
{
"a_id":108,
"a_value":110000.0,
"a_quantity":210.0
},
{
"a_id":104,
"a_value":105000.0,
"a_quantity":310.0
}
]
I would like the data to be sorted in descending order of a_value. I have tried:
a.sort_by {|k| k[:a_value] }.reverse
But it does not get sorted.
What you have works. Just don't forget to assign the sorted collection to a variable (sort_by and reverse do not change the collection).
Bonus: here's arguably a nicer version (one pass, instead of two)
a.sort_by{ |v| -v[:a_value] }
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Let's say you have some function that has one int parameter that can be good or bad. Let's say that it's bad when it's less than 5. And if it's bad you should get out of function. I think you already made up that function in your mind. Now tell me which of these functions is what you would've written.
1.
void abc(int a)
{
if (a < 5) return;
//...
}
2.
void abc(int a)
{
if (a >= 5)
{
//...
}
}
This may sound like a really stupid question. But I often have hard time deciding between these two lol.
I prefer the first way:
if a < 5
// return error or throw exception
To me it looks like some kind of "guard". Also you should handle this "bad" variable somehow (return error, throw exception) and it will be harder to follow if this is in some else block somewhere in the function.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Here is my code sample, let me know if it can be further improved?
excludedb = if File.exist?(arg)
IO.read(arg).split(',').map { |db_name| db_name.strip }.delete_if { |db_name| db_name == "" }
else
["master", "model", "sybsystemdb", "sybsystemprocs", "tempdb", "sybsecurity", "pubs2", "pubs3", "dbccdb", "sybmgmtdb"]
end
Here's a couple of tiny improvements.
You can replace
.map { |db_name| db_name.strip }
with
.map(&:strip)
And also you can use string array literal
%w{master model sybsystemdb}