YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Post a reply
From:
Message:

Maximum number of characters in each post is: 32767
Bold Italic Underline   Highlight Quote Code Insert Image Create Link   Left Justify Center Justify Right Justify   More BBCode Tags
Font Color: Font Size:
Security Image:
Enter Letters From Security Image:
  Preview Post Cancel

Last 10 Posts (In reverse order)
simonsilverport Posted: Monday, September 24, 2018 2:18:31 PM(UTC)
 
interesting question
mindchamber Posted: Thursday, May 25, 2017 8:13:59 PM(UTC)
 
Thank you very much, sir!
es Posted: Thursday, May 25, 2017 6:34:36 AM(UTC)
 
mindchamber wrote:
es wrote:
You might prefer something made for this task:
Code:
a.apply(@(v) v.tointeger());

It will be more productive than a cycle?

Yes because this is exactly why apply was made, and lambdas are officially recommended by the Squirrel manual to be used like this.

"Lambda expressions are a synctactic sugar to quickly define a function that consists of a single expression. This feature comes handy when functional programming patterns are applied, like map/reduce or passing a compare method to array.sort()."
('apply' internally uses 'map' and replaces the array with the return value from it. The code above is the equivalent of this:
Code:
a = a.map(@(v) v.tointeger());
)

This is also functionally equivalent code to the foreach statement suggested above but is a lot neater and focuses on what to do rather than how to do it.

However, if you prefer imperative programming over declarative, you would be fine with foreach.
mindchamber Posted: Thursday, May 25, 2017 6:15:54 AM(UTC)
 
es wrote:
You might prefer something made for this task:
Code:
a.apply(@(v) v.tointeger());

It will be more productive than a cycle?
es Posted: Wednesday, May 24, 2017 7:06:25 PM(UTC)
 
You might prefer something made for this task:
Code:
a.apply(@(v) v.tointeger());
mindchamber Posted: Sunday, May 21, 2017 10:57:42 PM(UTC)
 
Thank you!
Guest Posted: Sunday, May 21, 2017 8:25:14 PM(UTC)
 
foreach (index,element in a) {
a[index]=element.tointeger() ;
}

mindchamber Posted: Sunday, May 21, 2017 5:41:42 AM(UTC)
 
Hi, first sorry for my english)

I have string:
a = "1;2;3;4;5"

When i use split function ( split(a, ;) ) , i have this array:
a = ["1","2","3","4","5"]

how to transform type of array elements to integer?

Thanks.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.050 seconds.