Can you do list slicing in the Jac language? - jaseci

As the title suggests, is there a way to slice a list in Jac? something like,
short_list = original_list[3:5]

Yep,
Try running this in Jaseci:
walker init {
a=[1,2,3,4,5,6,7,8,9];
report a[4:7];
}

Related

getting issue in Dart

addorRemCcToList(EmployeeList item) {
print('add or');
print(_ccToListSelected.length);
print(_tempccToListSelected.length);
if (_tempccToListSelected.contains(item)) {
_tempccToListSelected.remove(item);
} else {
_tempccToListSelected.add(item);
}
print(_tempccToListSelected.length);
print(_ccToListSelected.length);
notifyListeners();
}
so this is a method through which i'm adding or removing items in _tempccToListSelected this list but the issue is when i make changes in _tempccToListSelected this list this _ccToListSelected list get the same changes and i didn't event touched it
as you can see in the picture it is the terminal showing the print result
You certainly have a line like this:
_tempccToListSelected = _ccToListSelected;
or the opposite.
This line don't copy list into another one but make a pointer to the other list (like in numerous language).
If you want to copy (duplicate) the liste use spread operator:
_tempccToListSelected = [..._ccToListSelected];
If you have code like this:
list1 = [];
list2 = list1;
this error is normal. You need give more information about this issue.

How can I manipulate a string in dart?

Currently I'm working in a project with flutter, but I realize there is a need in the management of the variables I'm using.
Basically I want to delete the last character of a string I'm concatenating, something like this:
string varString = 'My text'
And with the help of some method or function, the result I get:
'My tex'
Am I clear about it? I'm looking for some way which helps me to 'pop' the last character of a text (like pop function in javascript)
Is there something like that? I search in the Dart docs, but I didn't find anything about it.
Thank you in advance.
You can take a substring, like this:
string.substring(0, string.length - 1)
If you need the last character before popping, you can do this:
string[string.length - 1]
Strings in dart are immutable, so the only way to do the operation you are describing is by constructing a new instance of a string, as described above.
var str = 'My text';
var newStr = (str.split('')..removeLast()).join();
print(newStr);
Another way:
var newStr2 = str.replaceFirst(RegExp(r'.$') , '');
print(newStr2);

How to insert an option value into a select tag with CasperJS?

Well, the question is very self-explanatory.
Right now, I'm front of a form which has a select tag with a couple of options already. But I must insert a new one, with a different value that I will receive from a .json file.
The thing is: I haven't been able to find a suitable solution from the CasperJS documentation.
I've tried something like this:
this.fill('form.coworkerdiscountcode', {
'CoworkerDiscountCode.DiscountCode': ['Value1']
});
But no results. Any ideas?
Thanks in advance.
You can execute any javascript code by passing it to casper.evaluate like this:
casper.evaluate(function() {
var x = document.getElementById("coworkerdiscountcode");
var option = document.createElement("option");
option.text = "Kiwi";
x.add(option);
});

Take nth element of an Iterator

I have a scala Iterator[A]. How can I reference the nth element of it?
For instance:
val myIter: Iterator[Seq[String]] = { .... }
//get the size of the Iterator
val s = myIter.size
//get 3rd element (base 0)
val third:Seq[String] = myIter.get(2) <---- Something like this?
I maybe misreading the docs but can't find a function to do this easily. Thanks for help
If you want to live dangerously,
myIter.drop(2).next
or if you'd rather be safe
myIter.drop(2).take(1).toList.headOption
Quite simple
myIter.slice(n,n+1).toList.headOption
Drop.take will get all elements from the beginning. Slice is much more memory efficient

Google Charts: chxl and bhg

http://chart.apis.google.com/chart?cht=bhg&chd=t:3771.5,3220|5508.25,5366.75&
chs=400x200&chds=0,9000&chxt=x&chxr=0,0,9000&
chm=N*cUSD2s*,000000,0,-1,11|N*cUSD2s*,000000,1,-1,11&chco=4D89D9,C6D9FD
How to put label for each group?
chxl=1:|Mean|Median - should do something like this, but result is nothing
By groups I mean this numbers: 1 = { 3771.5, 5508.25 }, 2 = { 3220, 5366.75 }
Try appending this:
&chxt=x,y,r&chxl=2:|Mean|Median|
It might not be exactly what you want, but it works fine when I tried it.