Sort disjoint sublist: Difference between revisions

Content deleted Content added
Add Nimrod
Peak (talk | contribs)
jq
Line 762:
return values;
}</lang>
 
=={{header|jq}}==
We define a jq function that accepts the array of values as input:
<lang jq>def disjointSort(indices):
. as $values
| (indices|unique) as $ix # "unique" sorts
# Set $sorted to the sorted array of values at $ix:
| ( [ getpath( $ix|map([.]) | .[] ) ] | sort) as $sorted
| reduce range(0; $values|length) as $i
([];
. + [($ix|index($i)) as $j
| if $j == null then $values[$i]
else $sorted[$j]
end] ) ;
</lang>
Example:
<lang jq>
[7, 6, 5, 4, 3, 2, 1, 0] | disjointSort( [6, 1, 7] )
</lang>
produces:
[7,0,5,4,3,2,1,6]
 
=={{header|K}}==
Line 768 ⟶ 789:
7 0 5 4 3 2 1 6
</lang>
 
=={{header|Lua}}==
<lang lua>values = { 7, 6, 5, 4, 3, 2, 1, 0 }