Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/Libraries/CoreNodes/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,12 @@ public static IList Reorder(IList list, IList indices)
/// <returns name="int[]">The indices of the items in the sorted list</returns>
/// <search>sort,index,value</search>
[IsVisibleInDynamoLibrary(true)]
public static IEnumerable SortIndexByValue(List<double> list)
public static IEnumerable SortIndexByValue(IList list)
{
List<Tuple<int, double>> tupleList = new List<Tuple<int, double>>();
for (int i = 0; i < list.Count; i++)
{
tupleList.Add(new Tuple<int, double>(i, list[i]));
}
tupleList = tupleList.OrderBy(x => x.Item2).ToList();
IEnumerable<int> newList = tupleList.OrderBy(x => x.Item2).Select(y => y.Item1);
IEnumerable<int> newList = list.Cast<object>()
.Select((value, index) => new Tuple<int, object>(index, value))
.OrderBy(x => x.Item2, new ObjectComparer())
.Select(y => y.Item1);
return newList;
}

Expand Down
14 changes: 14 additions & 0 deletions test/Libraries/CoreNodesTests/ListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,20 @@ public static void SortIndexByValue()
{
Assert.AreEqual(new ArrayList { 4, 2, 3, 1, 0 }, List.SortIndexByValue(new List<double> { 8.0, 4.1, 2.0, 4.0, 0.0 }));
}

[Test]
[Category("UnitTests")]
public static void SortIndexByValue_WithIntegers()
{
Assert.AreEqual(new ArrayList { 4, 2, 1, 3, 0 }, List.SortIndexByValue(new List<int> { 8, 4, 2, 4, 0 }));
}

[Test]
[Category("UnitTests")]
public static void SortIndexByValue_WithMixedNumericTypes()
{
Assert.AreEqual(new ArrayList { 4, 2, 1, 3, 0 }, List.SortIndexByValue(new List<object> { 8.0, 4, 2.0, 4, 0 }));
}

[Test]
[Category("UnitTests")]
Expand Down
Loading