![]() |
detecting digits
Here's a tough question for you today forums :)
So let's say you have the number, 482 (just as an example) PHP Code:
The first digit being 2, the second being 8, and the third being 4. SO PHP Code:
|
Even though you are dealing with an integer substring should work.
PHP Code:
|
Quote:
|
Quote:
Quote:
|
Since we are dealing with numbers, I would approach it differently with some simple math.
PHP Code:
|
Quote:
PHP Code:
|
From my tests, the method I posted is faster then using substring. But I'm going to assume for OP's case it doesn't really mater which is more efficient.
|
Not saying you guys are wrong, but for me, Starfire's script is the only one I can really understand. Till new to scripting..
I'm still confused on what Return is doing in script..? |
Quote:
Quote:
|
Quote:
PHP Code:
you can set up a function to perform some actions, like sorting these numbers 54925 into an array. well once you've sorted them and put them into the array, you are telling the function to RETURN the data you've gathered or sorted when that function is called in the example above temp.digits = The Array the function numberToArray(temp.fullnumber) is returning... Hope that helps a bit... |
HTML Code:
this.fullnumber = 482; HTML Code:
function onCreated() { |
Quote:
I disagree with everybody. I would use .charat() PHP Code:
temp.num = 426; temp.test = numberToArray(num); temp.test is {4, 2, 6} You could also use charat() to most efficiently get the number at a single position, eg num.charat(1) would be 2. EDIT: Someone beat me to charat. Darn. But looping backwards and using .insert is the same as using .add and looping forwards, Andrew. EDIT2: I wonder if concatenation/tokenize would be more efficient than .add()? If so, temp.array = array SPC num.charat[i]; + tokenize it on the return. |
Yeah.
Well, the reason I used the backwards loop is because it's always quicker- well in JavaScript anyway https://blogs.oracle.com/greimer/ent..._way_to_code_a Not tested on Graal |
If we are talking about 'quickness': you are dealing with integers, treat them as integers.
|
| All times are GMT +2. The time now is 03:39 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.