How many are smaller than me?

JavaScript

function smaller(nums) {
  var smallerNums = [];
  for (var index = 0; index < nums.length; index++) {
    var numToCheck = nums[index];
    var smallerCount = 0;
    for (var remainingIndices = nums.length - index; remainingIndices > 0; remainingIndices--) {
      if (nums[index + remainingIndices] < numToCheck) smallerCount++;
    }

    smallerNums.push(smallerCount);
  }

  return smallerNums;
}

Tags

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