• Как пофиксить баг?

    Simkav
    @Simkav
    function putSpacesNumber(number) {
      if (typeof number !== 'number') {
        throw new TypeError('Argument must be a number');
      }
      if (number < 1000) {
        return number;
      }
      const arr = number.toString().split('');
      const result = [];
      const lengthdivineby3 = arr.length % 3;
      if (lengthdivineby3) {
        result.push(arr.slice(0, lengthdivineby3).join(''));
      }
      for (let i = lengthdivineby3; i < arr.length; i += 3) {
        result.push(' ', arr.slice(i, i + 3).join(''));
      }
      return result.join('').trim();
    }
    Ответ написан
    Комментировать