<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: array flat]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=16239&amp;type=atom" />
	<updated>2021-04-05T21:21:27Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=16239</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: array flat]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147178#p147178" />
			<content type="html"><![CDATA[<p>Вот так с указанием уровня вложенности:<br /></p><div class="codebox"><pre><code>FlatArray(arr, depth := 0xFFFFFFFF) {
   if (depth = 0)
      Return arr
   Loop % len := arr.Count() {
      i := len - A_Index + 1
      if IsObject(arr[i])
         arr.InsertAt(i, FlatArray(arr.RemoveAt(i), depth - 1)*)
   }
   Return arr
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-04-05T21:21:27Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147178#p147178</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: array flat]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147176#p147176" />
			<content type="html"><![CDATA[<p>Если нужно раскрывать независимо от уровня вложенности, то так:<br /></p><div class="codebox"><pre><code>arr := [1, 2, [3, 4, [5, 6, [7, 8]]]]
arrayFlat(arr)
for k, v in arr
   str .= (str ? &quot;, &quot; : &quot;&quot;) . v
MsgBox, % str

arrayFlat(arr) {
   Loop % len := arr.Count() {
      i := len - A_Index + 1
      if IsObject(item := arr[i]) {
         arr.RemoveAt(i)
         arr.InsertAt(i, arrayFlat(item)*)
      }
   }
   Return arr
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-04-05T19:30:13Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147176#p147176</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: array flat]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147171#p147171" />
			<content type="html"><![CDATA[<p>Пытаюсь сделать из массива:<br /></p><div class="codebox"><pre><code>[1, 2, [1, 3]]</code></pre></div><p>Массив:<br /></p><div class="codebox"><pre><code>[1, 2, 1, 3]</code></pre></div><p>Но что-то я подтупливаю:<br /></p><div class="codebox"><pre><code>arrayFlat(arr)
{
	newArr := []

	for i, v in arr
	{
		newArr.Push(IsObject(v) ? arrayFlat(v) : v)
	}

	return newArr
}</code></pre></div><p>UPD: Получилось что-то такое, как можно улучшить?<br /></p><div class="codebox"><pre><code>arrayFlat(arr, result := &quot;&quot;)
{
	if (!result)
	{
		result := []
	}

	for k, v in arr
	{
		if (isObject(v))
		{
			arrayFlat(v, result)
		}
		else
		{
			result.Push(v)
		}
	}

	return result
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2021-04-05T15:28:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147171#p147171</id>
		</entry>
</feed>
