diff --git a/src/Libraries/CoreNodes/List.cs b/src/Libraries/CoreNodes/List.cs index 86627959c43..85c03067e54 100644 --- a/src/Libraries/CoreNodes/List.cs +++ b/src/Libraries/CoreNodes/List.cs @@ -244,15 +244,12 @@ public static IList Reorder(IList list, IList indices) /// The indices of the items in the sorted list /// sort,index,value [IsVisibleInDynamoLibrary(true)] - public static IEnumerable SortIndexByValue(List list) + public static IEnumerable SortIndexByValue(IList list) { - List> tupleList = new List>(); - for (int i = 0; i < list.Count; i++) - { - tupleList.Add(new Tuple(i, list[i])); - } - tupleList = tupleList.OrderBy(x => x.Item2).ToList(); - IEnumerable newList = tupleList.OrderBy(x => x.Item2).Select(y => y.Item1); + IEnumerable newList = list.Cast() + .Select((value, index) => new Tuple(index, value)) + .OrderBy(x => x.Item2, new ObjectComparer()) + .Select(y => y.Item1); return newList; } diff --git a/test/Libraries/CoreNodesTests/ListTests.cs b/test/Libraries/CoreNodesTests/ListTests.cs index a8c556e220e..7f2b9614045 100644 --- a/test/Libraries/CoreNodesTests/ListTests.cs +++ b/test/Libraries/CoreNodesTests/ListTests.cs @@ -250,6 +250,20 @@ public static void SortIndexByValue() { Assert.AreEqual(new ArrayList { 4, 2, 3, 1, 0 }, List.SortIndexByValue(new List { 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 { 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 { 8.0, 4, 2.0, 4, 0 })); + } [Test] [Category("UnitTests")]