There are three types of edits that can be performed on strings: insert a character, remove a character, or replace a character. Given two strings, write a function to check if they are one edit (or zero edits) away.
Example:
pale, ple -> true
pales, pale -> true
pale, bale -> true
def one_away(a,b)
(a.split('')-b.split('')).count <= 1 ? true : false
end
# From Ruby 3.0, RSpec is used under the hood.
# See https://rspec.info/
# Defaults to the global `describe` for backwards compatibility, but `RSpec.desribe` works as well.
describe "Basic test" do
it "should true if edit is one or less" do
expect(one_away('pale', 'ple')).to eq(true)
expect(one_away('pales', 'pale')).to eq(true)
expect(one_away('pale', 'bale')).to eq(true)
expect(one_away('pale', 'pale')).to eq(true)
expect(one_away('pale', 'bake')).to eq(false)
end
end