GithubHelp home page GithubHelp logo

array_problem's Introduction

Array Utility exercise

ArrayUtils#sort_and_fill

  1. Write a ruby method that given an array of unsorted numbers returns the missing number in the natural range for that array.

USAGE:

This is how you run the specs:

➜  array_problem rspec

ArrayUtils
  #new
    takes an array and returns a util object
    raises an error when input isn't an array
  #sort_and_fill
    takes a short array and returns the same array
    fills array with one missing element
    fills array with multiple missing elements
    sorts and fills unsorted array with multiple missing elements
    sorts and fills array with missing elements in other sequence

Finished in 0.00429 seconds (files took 0.07648 seconds to load)
7 examples, 0 failures

How to use in the console:

➜  array_problem irb 

Frame number: 0/7
[1] pry(main)> load 'array_utils.rb'
=> true
[2] pry(main)> arr = ArrayUtils.new([1,2,3,4])
=> #<ArrayUtils:0x007fbb23a1aa50 @array=[1, 2, 3, 4]>
[3] pry(main)> arr.sort_and_fill
=> [1, 2, 3, 4]
[4] pry(main)> 

array_problem's People

Contributors

dgoldie avatar

Watchers

 avatar James Cloos avatar

array_problem's Issues

Handle gaps larger than the sequence

Example: [1, 2, 3, 5, 9, 27] -> [1, 2, 3, 5, 9, 10, 27]
only adds 10.

Should return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.