Largest 5 digit number in a series

JavaScript

function solution(digits) {
  var greatestNum = 0, sequenceLength = 5;
  for (var i = 0; i < digits.length - (sequenceLength - 1); i++) {
    var num = "";
    for (var j = 0; j < sequenceLength; j++) {
      num += digits[i + j];
    }

    num = parseInt(num);
    if (num > greatestNum) greatestNum = num;
  }

  return greatestNum;
}

Tags

  1. javascript (Private)
  2. 7-kyu (Private)
  3. codewars (Private)
  4. answer (Private)