Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 502d17c

Browse files
committed
Remove element
1 parent 218cab1 commit 502d17c

File tree

1 file changed

+18
-0
lines changed
  • CodingInterview/CodingInterview

1 file changed

+18
-0
lines changed

‎CodingInterview/CodingInterview/Tests.cs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ int[] LeaveTwoDuplicates(int[] arrayOfNumbers)
3737
return numbersWithTwoDuplicates.ToArray();
3838
}
3939

40+
int[] RemoveElement(int[] arrayOfNumbers, int elementToRemove)
41+
{
42+
return arrayOfNumbers.Where(element => element != elementToRemove)
43+
.ToArray();
44+
}
45+
4046
[Test]
4147
public void RemoveDuplicatesFromSortedArray_1()
4248
{
@@ -58,5 +64,17 @@ public void RemoveDuplicatesFromSortedArray_2()
5864

5965
Assert.AreEqual(expectedSortedArrayWithTwoDuplicates, sortedArrayWithTwoDuplicatesCalculated);
6066
}
67+
68+
[Test]
69+
public void RemoveElement_3()
70+
{
71+
var arrayWithElements = new int[] { 1, 5, 3, 3, 6, 1, 8, 3, 9, 7 };
72+
var expectedArrayWithElements = new int[] { 1, 5, 6, 1, 8, 9, 7 };
73+
var elementToRemove = 3;
74+
75+
var arrayWithRemoveElement = RemoveElement(arrayWithElements, elementToRemove);
76+
77+
Assert.AreEqual(expectedArrayWithElements, arrayWithRemoveElement);
78+
}
6179
}
6280
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /