Created
November 9, 2015 10:56
-
-
Save SergSlon/9f73f299d60403260f04 to your computer and use it in GitHub Desktop.
Revisions
-
SergSlon renamed this gist
Nov 9, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
SergSlon created this gist
Nov 9, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ var wordCase = function( num, words ) { var word = ''; num = Math.abs( num ); if ( num.toString().indexOf( '.' ) > -1 ) { word = words[ 2 ]; } else { word = ( num % 10 === 1 && num % 100 !== 11 ? words[ 1 ] : num % 10 >= 2 && num % 10 <= 4 && ( num % 100 < 10 || num % 100 >= 20) ? words[ 2 ] : words[ 0 ] ); } return word; }; /* использование: */ var words = [ 'яблок', 'яблоко', 'яблока' ];// [ 'ноль яблок', 'одно яблоко', 'два яблока' ] wordCase( 0, words );// яблок wordCase( 1, words );// яблоко wordCase( 2, words );// яблока wordCase( 5, words );// яблок wordCase( 10, words );// яблок