<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AKH: Сортировка массива.]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=14662&amp;type=atom" />
	<updated>2019-03-28T20:56:17Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=14662</id>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133219#p133219" />
			<content type="html"><![CDATA[<p>Ну вот, оказывается всё не так уж сложно. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-03-28T20:56:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133219#p133219</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133218#p133218" />
			<content type="html"><![CDATA[<p>Что-то типа этого вышло в итоге:<br /></p><div class="codebox"><pre><code>sortArray(array, key := &quot;&quot;, desc := 1, string := 0)
{
	str := &quot;&quot;, d1 := Chr(1), d2 := Chr(2)
	for k, v in array
		str .= (str = &quot;&quot; ? &quot;&quot; : d1) . (key ? v[key] : v) . d2 . k

	Sort, str, % (desc ? &quot;R&quot; : &quot;&quot;) (string ? &quot;&quot; : &quot;N&quot;) &quot;D&quot; . d1
	newArr := []
	Loop, parse, str, % d1
		newArr.Push(array[ RegExReplace(A_LoopField, &quot;.+&quot; . d2) ])
	return newArr
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2019-03-28T20:50:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133218#p133218</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133217#p133217" />
			<content type="html"><![CDATA[<p>Не думал что он подойдет, то есть просто заменить &quot;v[key]&quot; на &quot;v&quot; и дело в шляпе?</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2019-03-28T20:42:10Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133217#p133217</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133216#p133216" />
			<content type="html"><![CDATA[<p>Так а в чём трудность прменить тот же принцип для более простого случая?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-03-28T17:27:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133216#p133216</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133215#p133215" />
			<content type="html"><![CDATA[<p>А что насчет простого массива?<br /></p><div class="codebox"><pre><code>array := [13, 4, 1, 58, 25]</code></pre></div><p>Я находил код, но он слишком громоздкий и изменял основной массив (что-то по типу byRef).<br /></p><div class="codebox"><pre><code>SortArray(Array, Order := &quot;A&quot;)
{
	;Order A: Ascending, D: Descending, R: Reverse
	MaxIndex := ObjMaxIndex(Array)
	If (Order == &quot;R&quot;)
	{
		count := 0
		Loop, % MaxIndex
			ObjInsert(Array, ObjRemove(Array, MaxIndex - count++))
		Return
	}
	Partitions := &quot;|&quot; ObjMinIndex(Array) &quot;,&quot; MaxIndex
	Loop
	{
		comma := InStr(this_partition := SubStr(Partitions, InStr(Partitions, &quot;|&quot;, False, 0)+1), &quot;,&quot;)
		spos := pivot := SubStr(this_partition, 1, comma-1) , epos := SubStr(this_partition, comma+1)
		if (Order == &quot;A&quot;)
		{
			Loop, % epos - spos
			{
				if (Array[pivot] &gt; Array[A_Index+spos])
					ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
			}
		}
		else
		{
			Loop, % epos - spos
			{
				if (Array[pivot] &lt; Array[A_Index+spos])
					ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
			}
		}
		Partitions := SubStr(Partitions, 1, InStr(Partitions, &quot;|&quot;, False, 0)-1)
		if (pivot - spos) &gt; 1    ;if more than one elements
			Partitions .= &quot;|&quot; spos &quot;,&quot; pivot-1        ;the left partition
		if (epos - pivot) &gt; 1    ;if more than one elements
			Partitions .= &quot;|&quot; pivot+1 &quot;,&quot; epos        ;the right partition
	}
	Until !Partitions
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2019-03-28T14:59:02Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133215#p133215</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133070#p133070" />
			<content type="html"><![CDATA[<p>Вот так корректнее:<br /></p><div class="codebox"><pre><code>arr := [ {id: 43, isAFK: 1, nick: &quot;Thiago_Montesdeoca&quot;, rankNum:  2}
       , {id: 40, isAFK: 0, nick: &quot;kukumba&quot;           , rankNum: 10}
       , {id:  5, isAFK: 1, nick: &quot;blackboss&quot;         , rankNum:  3} ]
key := &quot;rankNum&quot;

str := &quot;&quot;, d1 := Chr(1), d2 := Chr(2)
for k, v in arr
   str .= (str = &quot;&quot; ? &quot;&quot; : d1) . v[key] . d2 . k

Sort, str, % &quot;D&quot; . d1
newArr := []
Loop, parse, str, % d1
   newArr.Push(arr[ RegExReplace(A_LoopField, &quot;.+&quot; . d2) ])

for k, v in newArr
   MsgBox, % v.nick</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-03-22T21:44:47Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133070#p133070</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133068#p133068" />
			<content type="html"><![CDATA[<p><a href="https://autohotkey.com/docs/Variables.htm#concat">Здесь</a>.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-03-22T16:49:48Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133068#p133068</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133067#p133067" />
			<content type="html"><![CDATA[<p>Где можно прочитать про точку? Не раз замечал ее присутствие, но думал это проделки PHP <img src="//forum.script-coding.com/img/smilies/big_smile.png" width="15" height="15" />.</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2019-03-22T16:46:29Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133067#p133067</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133066#p133066" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>Sort, str, % &quot;RD&quot; . d</code></pre></div><p>После точки пробел нужен. Или по-другому:</p><div class="codebox"><pre><code>Sort, str, RD%d%</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-03-22T16:45:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133066#p133066</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133065#p133065" />
			<content type="html"><![CDATA[<p>Что-то не получается у меня добавить &quot;R&quot;, как и куда правильно ее добавить?<br />Пробовал и с пробелом и без, не дало результатов.<br /></p><div class="codebox"><pre><code>Sort, str, % &quot;D&quot; .d &quot;R&quot;
Sort, str, % &quot;D&quot; .d &quot; R&quot;
Sort, str, % &quot;RD&quot; .d
Sort, str, % &quot;R D&quot; .d</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2019-03-22T16:37:37Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133065#p133065</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133064#p133064" />
			<content type="html"><![CDATA[<p>Так смотрите хелп по Sort, там всё есть.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-03-22T16:23:47Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133064#p133064</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133063#p133063" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong>, а можно как-то обратную сортировку? (DESC)</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2019-03-22T16:15:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133063#p133063</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133059#p133059" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Phoenixxx_Czar пишет:</cite><blockquote><p>Можно какой-то пример?</p></blockquote></div><p>Готового примера нет, а писать лень.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-03-22T15:35:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133059#p133059</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133058#p133058" />
			<content type="html"><![CDATA[<p>Я так и не понял, зачем нужно было в JSON переводить.<br /></p><div class="codebox"><pre><code>arr := [ {id: 43, isAFK: 1, nick: &quot;Thiago_Montesdeoca&quot;, rankNum:  2}
       , {id: 40, isAFK: 0, nick: &quot;kukumba&quot;           , rankNum: 10}
       , {id:  5, isAFK: 1, nick: &quot;blackboss&quot;         , rankNum:  3} ]
key := &quot;rankNum&quot;

str := &quot;&quot;, d := Chr(1)
for k, v in arr
   str .= (str = &quot;&quot; ? &quot;&quot; : d) . v[key] . &quot;~&quot; . k

Sort, str, % &quot;D&quot; . d
newArr := []
Loop, parse, str, % d
   newArr.Push(arr[ RegExReplace(A_LoopField, &quot;.+~&quot;) ])

for k, v in newArr
   MsgBox, % v.nick</code></pre></div><p>Это строчная сортировка. Для числовой добавьте N к опциям Sort.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-03-22T15:35:56Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133058#p133058</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AKH: Сортировка массива.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=133057#p133057" />
			<content type="html"><![CDATA[<p>AHK массива.</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2019-03-22T15:14:15Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=133057#p133057</id>
		</entry>
</feed>
