Skip to content

Instantly share code, notes, and snippets.

@ghalimi
Created January 27, 2013 18:51
Show Gist options
  • Save ghalimi/4649740 to your computer and use it in GitHub Desktop.
Save ghalimi/4649740 to your computer and use it in GitHub Desktop.
SYD Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function SYD(cost, salvage, life, period) {
// Return error if any of the parameters is not a number
if (isNaN(cost) || isNaN(salvage) || isNaN(life) || isNaN(period)) return '#VALUE!';
// Return error if life equal to 0 (zero)
if (life === 0) return '#NUM!';
// Return error if period is lower than 1 or greater than life
if (period < 1 || period > life) return '#NUM!';
// Truncate period if it is not an integer
period = parseInt(period, 10);
// Return straight-line depreciation
return (cost - salvage) * (life - period + 1) * 2 / (life * (life + 1));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment