countSalutes

kata

by trentHarlem

JavaScript

function countSalutes(hallway) {
  let salutes = 0
  let remain = []
  array = hallway.split('')
  array.forEach((item, i) => {
    if (item === '>') {
      remain = array.slice([i]);
      remain.forEach(elem => {
        if (elem === '<')
          salutes = salutes + 2;
      })
    }
  });
  return salutes
}

console.log(countSalutes('<---->---<---<-->'), 4);
//console.log(countSalutes('------'), 0);
//console.log(countSalutes('>>>>>>>>>>>>>>>>>>>>>----<->'), 42);
//console.log(countSalutes('<<----<>---<'), 2);
//console.log(countSalutes('>'), 0);