7 kyu

Sort Numbers

26,134 of 64,579jhoffner

Description:

Finish the solution so that it sorts the passed in array of numbers. If the function passes in an empty array or null/nil value then it should return an empty array.

For example:

solution(c(1, 2, 3, 10, 5)) # should return c(1, 2, 3, 5, 10)
solution(NULL)              # should return NULL
solution([1, 2, 10, 50, 5]); // should return [1,2,5,10,50]
solution(null); // should return []
solution([1, 2, 10, 50, 5]); // should return [1,2,5,10,50]
solution(null); // should return []
solution([1, 2, 10, 50, 5]); // should return [1, 2, 5, 10, 50]
solution([]); // should return []
solution([1, 2, 10, 50, 5]) # should return [1,2,5,10,50]
solution(null) # should return []
solution([1, 2, 10, 50, 5]) # should return [1,2,5,10,50]
solution(nil) # should return []
solution([1,2,3,10,5]) # should return [1,2,3,5,10]
solution(None) # should return []
solution([1, 2, 10, 50, 5]) # should return [1,2,5,10,50]
solution(nothing) # should return []
SortNumbers(new int[] { 1, 2, 10, 50, 5 }); // should return new int[] { 1, 2, 5, 10, 50 }
SortNumbers(null); // should return new int[] { }
sort_numbers(&vec![1, 2, 3, 10, 5]); // should return vec![1, 2, 3, 5, 10]
sort_numbers(&vec![]); // should return !vec[]
sortNumbers [1, 2, 10, 50, 5] = Just [1, 2, 5, 10, 50]
sortNumbers [] = Nothing
# (Note in Lambda Calculus we have lists instead of arrays.)
nums = cons 1 (cons 2 (cons 10 (cons 50 (cons 5 nil))))
sort nums # cons 1 (cons 2 (cons 5 (cons 10 (cons 50 nil))))
sortNumbers({1, 2, 10, 50, 5}) // sholud return {1, 2, 5, 10, 50}
sortNumbers({}) // should return {}
int array[5] = {1, 2, 10, 50, 5};
sort_ascending(5, array); // array is now {1, 2, 5, 10, 50}
sort_ascending(0, NULL); // nothing to do for empty array
      SortNumbers([1, 2, 10, 50, 5])
      *  -> res = [1, 2, 5, 10, 50]
      SortNumbers([])
      *  -> res = []
sol(List(0, 3, 2, 5, 4, 1)) // returns List(0, 1, 2, 3, 4, 5)
sol(List()) // returns List()
solution([1, 2, 10, 50, 5]) # should return [1,2,5,10,50]
solution(nil) # should return [] of Int32
Fundamentals

Similar Kata:

Stats:

CreatedApr 22, 2013
PublishedApr 22, 2013
Warriors Trained86500
Total Skips5807
Total Code Submissions177232
Total Times Completed64579
JavaScript Completions26134
CoffeeScript Completions443
Ruby Completions4143
Python Completions20280
C# Completions2769
Rust Completions1483
Haskell Completions414
TypeScript Completions2076
R Completions532
C++ Completions3480
Clojure Completions268
Julia Completions64
PHP Completions1348
Go Completions2132
COBOL Completions14
C Completions641
λ Calculus Completions12
Scala Completions115
Crystal Completions9
Total Stars382
% of votes with a positive feedback rating89% of 4456
Total "Very Satisfied" Votes3640
Total "Somewhat Satisfied" Votes665
Total "Not Satisfied" Votes151
Ad
Contributors
  • jhoffner Avatar
  • glebec Avatar
  • El Corto Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • user5036852 Avatar
  • JohanWiltink Avatar
  • a.merezhanyi Avatar
  • Voile Avatar
  • Souzooka Avatar
  • KenKamau Avatar
  • rsa Avatar
  • hobovsky Avatar
  • khlivnyuk Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • nmburaleh Avatar
  • ejini战神 Avatar
  • kvbc Avatar
  • akar-0 Avatar
  • zakro Avatar
  • dfhwze Avatar
  • KayleighWasTaken Avatar
  • AmirTallap Avatar
Ad