Notifications
Clear all

[Closed] Array value indexing

Hi, Im building a mesh importer and have stumbled across a problem that I cant figure out, so I`d be grateful if someone could shed some light on this.
so I have this “boneIndex_array” which looks something like this
(1,1,1,1,3,3,3,10,10,1,1,1,2,2,2,2,5,5,5,8,8,8,8,1,1,1,1,3,3,3,3,3,3,3,…) now I want to find all start and end indexes of value “1” then “3” then “5” so that the resulting array would look like this ((1…4,10…12,24…27)(5…7,28…34)(17…19)and so on)

findItem returns only first found index of the value :shrug:
Anyone would have some suggestions?

thanks

2 Replies

maybe something like this:

(
	fn findItemIndexes arr =
	(
		local usedValues = #()
		local indexes = #()
		for i = 1 to arr.count do (
			local j = findItem usedValues arr[i]
			if j == 0 then (
				append usedValues arr[i]
				append indexes #{i}
			) else
				indexes[j][i] = on
		)
		indexes
	)
	
	local test = #(1,1,1,1,3,3,3,10,10,1,1,1,2,2,2,2,5,5,5,8,8,8,8,1,1,1,1,3,3,3,3,3,3,3)
	findItemIndexes test
)

or if you want to find only the indexes of a specific value x then something like:

(
	fn findItemIndexes arr x =
	(
		local indexes = #{}
		for i = 1 to arr.count do (
			if arr[i] == x then
				indexes[i] = on
		)
		indexes
	)
	
	local test = #(1,1,1,1,3,3,3,10,10,1,1,1,2,2,2,2,5,5,5,8,8,8,8,1,1,1,1,3,3,3,3,3,3,3)
	findItemIndexes test 3
)

Works like a charm.

Thank you so much MatanH