6 kyu

Another one down—the Survival of the Fittest!

421 of 788bkaes

Description:

Stuck? [Try this one](http://www.codewars.com/kata/remove-the-minimum).

A Storm at Sea

Jill the adventurer has seen everything, from the highest mountains, to the most dangerous animals. But today she sailed through a hideous storm and shipwrecked. Left with only a damaged life boat and some supplies, she has carefully balanced out the weight not to capsize. But the weight is too much for the small life boat, she has to get rid of some items.

Beginning from one side of the boat, she starts to remove the n smallest items and hopes for the best…

Task

Given an array of integers, remove the n smallest. If there are multiple elements with the same value, remove the ones with a lower index first. If n is greater than the length of the array/list, return an empty list/array. If n is zero or less, return the original array/list.

Don't change the order of the elements that are left.

Examples

removeSmallest (-10) [1,2,3,4,5] = [1,2,3,4,5]
removeSmallest 0 [1,2,3,4,5] = [1,2,3,4,5]
removeSmallest 2 [5,3,2,1,4] = [5,3,4]
removeSmallest 3 [5,3,2,1,4] = [5,4]
removeSmallest 3 [1,2,3,4,5] = [4,5]
removeSmallest 5 [1,2,3,4,5] = []
removeSmallest 9 [1,2,3,4,5] = []

removeSmallest 2 [1,2,1,2,1] = [2,2,1]
removeSmallest (-10) [1,2,3,4,5] = [1,2,3,4,5]
removeSmallest 0 [1,2,3,4,5] = [1,2,3,4,5]
removeSmallest 2 [5,3,2,1,4] = [5,3,4]
removeSmallest 3 [5,3,2,1,4] = [5,4]
removeSmallest 3 [1,2,3,4,5] = [4,5]
removeSmallest 5 [1,2,3,4,5] = []
removeSmallest 9 [1,2,3,4,5] = []

removeSmallest 2 [1,2,1,2,1] = [2,2,1]
removeSmallest (-10) [1,2,3,4,5] = [1,2,3,4,5]
removeSmallest 0 [1,2,3,4,5] = [1,2,3,4,5]
removeSmallest 2 [5,3,2,1,4] = [5,3,4]
removeSmallest 3 [5,3,2,1,4] = [5,4]
removeSmallest 3 [1,2,3,4,5] = [4,5]
removeSmallest 5 [1,2,3,4,5] = []
removeSmallest 9 [1,2,3,4,5] = []

removeSmallest 2 [1,2,1,2,1] = [2,2,1]
remove_smallest ((-10), [1,2,3,4,5]) = [1,2,3,4,5]
remove_smallest (0, [1,2,3,4,5]) = [1,2,3,4,5]
remove_smallest (2, [5,3,2,1,4]) = [5,3,4]
remove_smallest (3, [5,3,2,1,4]) = [5,4]
remove_smallest (3, [1,2,3,4,5]) = [4,5]
remove_smallest (5, [1,2,3,4,5]) = []
remove_smallest (9, [1,2,3,4,5]) = []

remove_smallest (2, [1,2,1,2,1]) = [2,2,1]
remove_smallest((-10), [1,2,3,4,5]) = [1,2,3,4,5]
remove_smallest(0, [1,2,3,4,5]) = [1,2,3,4,5]
remove_smallest(2, [5,3,2,1,4]) = [5,3,4]
remove_smallest(3, [5,3,2,1,4]) = [5,4]
remove_smallest(3, [1,2,3,4,5]) = [4,5]
remove_smallest(5, [1,2,3,4,5]) = []
remove_smallest(9, [1,2,3,4,5]) = []

remove_smallest(2, [1,2,1,2,1]) = [2,2,1]
Lists
Arrays
Fundamentals

Stats:

CreatedNov 6, 2015
PublishedNov 6, 2015
Warriors Trained1738
Total Skips165
Total Code Submissions6006
Total Times Completed788
Haskell Completions75
JavaScript Completions275
CoffeeScript Completions13
Python Completions421
Ruby Completions52
Total Stars43
% of votes with a positive feedback rating93% of 199
Total "Very Satisfied" Votes174
Total "Somewhat Satisfied" Votes21
Total "Not Satisfied" Votes4
Total Rank Assessments25
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • bkaes Avatar
  • CrazyMerlyn Avatar
  • NaMe613 Avatar
  • smile67 Avatar
  • FArekkusu Avatar
  • solitude Avatar
  • saudiGuy Avatar
Ad