objects of reverse geocoding in ionic 2 - ionic2

When i'm using this
this.nativeGeocoder.reverseGeocode(parseFloat(this.myLat),parseFloat( this.myLong))
.then((result: NativeGeocoderReverseResult) =>
{ console.log('The address is ' + result.street + ' in ' + result.countryCode)
in a function called in constructor i'm getting-
The address is Unnamed Road in IN
result.street is not working
!

You must update result.street to result[0].street
It will work
This
this.nativeGeocoder.reverseGeocode(parseFloat(this.myLat),parseFloat( this.myLong))
.then((result: NativeGeocoderReverseResult) =>
{ console.log('The address is ' + result.street + ' in ' + result.countryCode)
To
this.nativeGeocoder.reverseGeocode(parseFloat(this.myLat),parseFloat( this.myLong))
.then((result: NativeGeocoderReverseResult) =>
{ console.log('The address is ' + result[0].street + ' in ' + result[0].countryCode)

Related

C++ "Too many initializers" Error while making an array of chars

I'm new to C++. I know a lot of python but I'm extremely new to C++. I was creating an array of chars but I got this error- "Too many Initializers" in VSCode.
Please let me know how to fix it.
Here's the code
1 | class Board {
2 | public:
3 | char pos_list[9];
4 |
5 | void reset_pos() {
6 | pos_list[9] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
7 | };
8 | };
I am getting this error in line 6.
Please help me :(
EDIT: My initial answer was not correct, please find the modified correct way to do what you are looking for:
You will not be able to use {'','',''} in order to assign empty values to all elements in the array in C++, you can only do that while initializing the array when you declare it. Also, it wouldn't be ideal because it would use hardcoding of ' ' across the entire length of the array. The better way to do this is to loop over the array and then set each element to empty like below:
void reset_pos() {
int len = sizeof(pos_list)/sizeof(pos_list[0]);
for(int i=0; i<len; i++){
pos_list[i] = ' ';
}
};

Invalid Syntax with Print Statement

I have a line of code that is saying that there is invalid syntax in my print statement. Does anyone know about how to fix this? I've tried deleting the parentheses and have tried changing the +'s to ,'s.
print(stockName[random] + ' - $' + Names[0, amod] + ' : You have ' + x + ' of this stock')
If you use ' x ' with + operator it should be a string else you should use coma.

Python- How to change lists order in a list of lists

I have a list of lists that i want to put in order with the times that a person leaves he's job. I already made a code to give me only the time but i need something to check the times and put them in order.
inFile=removeHeader(file_name) # the information is taken from a txt file and this only gives me the part of the services
#print inFile gives me list of lists like [['Peter', ' 06-CB-89', ' Xavier', ' 09:45', ' 10:15', ' downtown', ' 10', ' standby'], ['Robert', ' 13-KI-54', ' Paul', ' 09:30', ' 10:30', ' Castle', ' 45', ' standby']
for time in inFile:
hours=time[4]
print hours #this gives me only the hours they left work
see https://docs.python.org/2/library/functions.html#sorted
you have to sort the main list by the leave time i.e. the 5th value of the sublists, the key argument of sorted alows you to specify a function that will be called to compute keys the list is sorted based on:
import time
x =[['Peter', ' 06-CB-89', ' Xavier', ' 09:45', ' 10:15', ' downtown', ' 10', ' standby'], ['Robert', ' 13-KI-54', ' Paul', ' 09:30', ' 10:30', ' Castle', ' 45', ' standby']]
sorted(x, key = lambda x: x[4])

Validate range of decimal numbers in javascript using regex

I have a condition to validate a number. My requirement is accept only following numbers.
0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5
I tried with this regex but it returns false for decimal numbers.
/^[0|0.5|1|1.5|2|2.5|3|3.5|4|4.5|5]$/
The system that I am working is an existing system and I must use regular expression. No other option available for me.
Can anyone help me?
Your expression is almost correct:
/^(0|0\.5|1|1\.5|2|2\.5|3|3\.5|4|4\.5|5)$/
You need to use round brackets instead of square brackets and escape the dots. Round brackets indicate groups while square brackets define a group of single characters which may be matched. A shorter variant is this:
/^([0-4](\.5)?|5)$/
This will match any digit from 0 to 4, optionally followed by .5, or the single digit 5.
You may try the below regex.
^(?:[0-4](?:\.5)?|5)$
[0-4] will match range of digits from 0 to 4.
(?:\.5)? optional .5
DEMO
Instead of using regexes, you should really see if you can use a function.
This would be your best option, then:
function check(num) {
var floored = Math.floor(num);
return (num === floored || num - 0.5 === floored) && num >= 0 && num <=5;
}
alert(1 + ' ' + check(1) + '\n' +
5 + ' ' + check(5) + '\n' +
6 + ' ' + check(6) + '\n' +
1.5 + ' ' + check(1.5) + '\n' +
4.5 + ' ' + check(4.5) + '\n' +
5.5 + ' ' + check(5.5) + '\n' +
5.51 + ' ' + check(5.51) + '\n' +
-1.5 + ' ' + check(-1.5) + '\n' +
-0.5 + ' ' + check(-0.5))

Python list efficientcies: bulk conversion of variables to str and list generation

So con is simply a condition that I am matching coming from a date generator I built. All output from this function is immutable. So I had the 'awesome' task of converting these outputs to strings. Reason being I wanted to append/prepend markup to the output. This gets very cumbersome when dealing with a lot of variables. 365 days to be exact.
con0 = str(context[0])
con1 = str(context[1])
con2 = str(context[2])
con3 = str(context[3])
con4 = str(context[4])
con5 = str(context[5])
con6 = str(context[6])
con7 = str(context[7])
con8 = str(context[8])
con9 = str(context[9])
con10 = str(context[10])
con11 = str(context[11])
con12 = str(context[12])
...
con364 = str(context[364])
day0 = con0[0:10].replace("-", "");
day1 = con1[0:10].replace("-", "");
day2 = con2[0:10].replace("-", "");
day3 = con3[0:10].replace("-", "");
day4 = con4[0:10].replace("-", "");
day5 = con5[0:10].replace("-", "");
day6 = con6[0:10].replace("-", "");
day7 = con7[0:10].replace("-", "");
day8 = con8[0:10].replace("-", "");
day9 = con9[0:10].replace("-", "");
day10 = con10[0:10].replace("-", "");
day11 = con11[0:10].replace("-", "");
day12 = con12[0:10].replace("-", "");
...
day364 = con364[0:10].replace("-", "");
exclude = [ ' "/' + year0 + "/" + day0 + "*" + '"', ' "/' + year0 + "/" + day1 + "*" + '"', ' "/' + year0 + "/" + day2 + "*" + '"', ' "/' + year0 + "/" + day3 + "*" + '"', ' "/' + year0 + "/" + day4 + "*" + '"', ' "/' + year0 + "/" + day5 + "*" + '"', ' "/' + year0 + "/" + day6 + "*" + '"', ' "/' + year0 + "/" + day7 + "*" + '"', ' "/' + year0 + "/" + day8 + "*" + '"', ' "/' + year0 + "/" + day9 + "*" + '"', ' "/' + year0 + "/" + day10 + "*" + '"', ' "/' + year0 + "/" + day11 + "*" + '"', ' "/' + year0 + "/" + day12 ... + year0 + "/" + day364 + "*" + '"' ]
d0 = ' "*%s*"\n' % (day0)
y0 = ' "/%s/*"\n' % (year0)
w0 = ' %s\n'' %s\n'' %s\n'' %s\n'' %s\n'' %s\n'' %s\n'' %s\n'' %s\n'' %s\n'' %s\n'' %s\n'' %s\n' % (exclude[7],exclude[8],exclude[9],exclude[10],exclude[11],exclude[12]....exclude[364])
Is there a more pythonic way to make bulk string substitutions and generate lists easier than using my for i bash loops to build them for me?
When you have many variables all ending with a number, that's an excellent sign that you should be using a single list instead. You can concisely construct a list using list comprehensions.
cons = [str(context[i]) for i in range(365)]
days = [con[0:10].replace("-", "") for con in cons]
exclude = [' "/{}/{}*"'.format(year0, day) for day in days]
w0 = "\n".join(" " + day for for day in days)