Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6468857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:55:44+00:00 2026-05-25T05:55:44+00:00

I have the following method for doing a check digit on a tracking number,

  • 0

I have the following method for doing a check digit on a tracking number, but it just feels lengthy/sloppy. Can it be refactored and just generally cleaned up?

I’m running Ruby 1.8.7.

def is_fedex(number)
  n = number.reverse[0..14]

  check_digit = n.first.to_i

  even_numbers = n[1..1].to_i + n[3..3].to_i + n[5..5].to_i + n[7..7].to_i + n[9..9].to_i + n[11..11].to_i + n[13..13].to_i

  even_numbers = even_numbers * 3

  odd_numbers = n[2..2].to_i + n[4..4].to_i + n[6..6].to_i + n[8..8].to_i + n[10..10].to_i + n[12..12].to_i + n[14..14].to_i

  total = even_numbers + odd_numbers

  multiple_of_ten = total + 10 - (total % 10)

  remainder = multiple_of_ten - total

  if remainder == check_digit
    true
  else
    false
  end
end

EDIT: Here are valid and invalid numbers.

Valid: 9612019950078574025848

Invalid: 9612019950078574025847

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:55:44+00:00Added an answer on May 25, 2026 at 5:55 am
    def is_fedex(number)
      total = (7..20).inject(0) {|sum, i| sum + number[i..i].to_i * ( i.odd? ? 1 : 3 ) }
      number[-1].to_i == (total / 10.0).ceil * 10 - total
    end
    

    I believe you should keep your code. While it’s not idiomatic or clever, it’s the one you will have the least trouble to understand a few months from now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best method of doing the following: I have Page A with
In some crunching number program, I have a function which can be just 1
I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have the following method in my code: private bool GenerateZipFile(List<FileInfo> filesToArchive, DateTime archiveDate)
I have the following method: private JobCard PopulateObject(JobCard jc, DataRow dataRow) { PropertyInfo[] proplist
I have the following method that is replacing a pound sign from the file
I have the following method public static void SerializeToXMLFile(Object obj,Type type, string fileName) {
I have the following method that is supposed to be a generic Save to
i have the following method in a usercontrol protected override void Render(HtmlTextWriter writer) {
I have the following method and interface: public object ProcessRules(List<IRule> rules) { foreach(IRule rule

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.