c# - Function to look through list and determine trend -


so have list of items. each item on list has property called notional. now, list sorted. need is, develop function sets type of list 1 of following:

  • bullet - notional same every item
  • amortizing - notional decreases on course of schedule (might stay same element element should never go up, , should end lower)
  • accreting - notional increases on course of schedule (might stay same element element should never go down, , should end higher)
  • rollercoaster - notional goes , down (could end same, higher, or lower, shouldn't same each element , shouldn't classfied other types)

what method , efficient way go through list , figure out?

thanks!

this straightforward way it:

bool hasgoneup = false; bool hasgonedown = false; t previous = null; // t type of objects in list; assuming ref type  foreach(var item in list) {     if (previous == null) {         previous = item;         continue;     }      hasgoneup = hasgoneup || item.notional > previous.notional;     hasgonedown = hasgonedown || item.notional < previous.notional;      if(hasgoneup && hasgonedown) {         return trend.rollercoaster;     }      previous = item; }  if (!hasgoneup && !hasgonedown) {     return trend.bullet; }  // 1 of hasgoneup , hasgonedown true point return hasgoneup ? trend.accreting : trend.amortizing; 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -