M
M
medianoche2015-05-28 03:29:00
JavaScript
medianoche, 2015-05-28 03:29:00

Is this shitcode or JS norm?

If a programmer writes such JS code:

money = 1500;

var strMoney = money.toString();
var endNum = strMoney.substr(strMoney.length - 1); // последняя цифра числа
var preEndNum = strMoney.slice(strMoney.length - 2, -1); // предпоследняя цифра числа

var moneyName = "рублей";
if (endNum == 1 && preEndNum != 1) {
  moneyName = "рубль";
} else if (endNum >= 2 && endNum <=4 && preEndNum != 1) {
  moneyName = "рубля";
}

1. What can be said about the quality of his work? Is this bullshit and normal?
2. If a programmer bothers with such things, instead of displaying "rubles", does this characterize him from a positive or negative side?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
M
Mark, 2015-05-28
@medianoche

1. the code is bad, I send it to the code review to rewrite it
2. the undertaking is good, it is necessary to praise (but still make it redo normally)

Y
Yuri Yarosh, 2015-05-28
@voidnugget

1. This is the code of a person who did not bother to look for any existing internationalization library, or who got acquainted with Intl 'th for which there are quite sane polyfills .
2. This characterizes him as a person who wants to do "well", but it turns out "as always" due to lack of knowledge and experience.

A
Alexey Nikolaev, 2015-05-28
@Heian

From an algorithmic point of view and some other points (for example, the constant use of var), it's more shitty code than not, an acceptable average level is 5 \ 10. But it's hard to judge the whole code from this piece - it's too simple.
If in the layout \ TK it was clearly written "rubles", then this characterizes him as a person who is attentive to detail. This is a positive quality.
PS Libraries for declension of numeral nouns are redundant in this case.

V
Vitaly Pukhov, 2015-05-28
@Neuroware

1. If this code really covers all variations of combinations, then the code is normal.
2. Depends on whether it was necessary to display it, if the designer did not leave extra space for an additional "lay", then this can spoil the look of the page.

D
Denis Ineshin, 2015-05-28
@IonDen

But he could just write "rub." ) so that will do.

O
OlegTar, 2015-06-15
@OlegTar

1. Not shitty code (I ran the tests, and everything passes), but I would rewrite to check the remainder of the division, and not to check the digits in the number.
2. Positive, attentive to detail

O
OnYourLips, 2015-05-28
@OnYourLips

1. Shit code. Errors are not checked, he does not know arithmetic, he does too much.
2. Positively, because he completed the task as required.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question