rename common util selectItem -> select

This commit is contained in:
tmshv committed 2016-02-22 04:36:22 +03:00
1 parent 78cbb576e3
commit dca671c564
3 files changed
+9 -9

No files matched your search

+2 -2
View File
@@ -1,7 +1,7 @@
import {populate} from '../../utils/populate'; import {populate} from '../../utils/populate';
import {getCourseNameByID} from '../../models/course'; import {getCourseNameByID} from '../../models/course';
import {indexEquals} from '../../utils/common'; import {indexEquals} from '../../utils/common';
import {selectItem} from '../../utils/common'; import {select} from '../../utils/common';
function isRequested(period, semester) { function isRequested(period, semester) {
return function (schedule) { return function (schedule) {
@@ -24,7 +24,7 @@ export default function (app) {
schedules = schedules.map(schedule => { schedules = schedules.map(schedule => {
let sem = [['spring', 'Весена'], ['autumn', 'Осень']] let sem = [['spring', 'Весена'], ['autumn', 'Осень']]
.reduce(selectItem( .reduce(select(
i => i[0] === schedule.semester, i => i[0] === schedule.semester,
i => i[1] i => i[1]
)); ));
+1 -1
View File
@@ -39,6 +39,6 @@ export function indexEquals(withNumber) {
* @param byCondition * @param byCondition
* @param map * @param map
*/ */
export function selectItem(byCondition, map = i => i) { export function select(byCondition, map = i => i) {
return (result, item) => byCondition(item) ? map(item): map(result) return (result, item) => byCondition(item) ? map(item): map(result)
} }
+6 -6
View File
@@ -1,18 +1,18 @@
import should from 'should'; import should from 'should';
import {selectItem} from '../../src/utils/common'; import {select} from '../../src/utils/common';
describe('utils', () => { describe('utils', () => {
describe('common.js', () => { describe('common.js', () => {
describe('selectItem', () => { describe('selectItem', () => {
it('should return a function', () => { it('should return a function', () => {
let fn = selectItem(); let fn = select();
fn.should.be.type('function'); fn.should.be.type('function');
}); });
it('should accept a function as a first parameter and use it as byCondition', () => { it('should accept a function as a first parameter and use it as byCondition', () => {
let sample = [[1235, 'hello'], [2352, 'banana']]; let sample = [[1235, 'hello'], [2352, 'banana']];
let fn = selectItem( let fn = select(
i => i[0] === 2352 && i[1] === 'banana' && i.length === 2, i => i[0] === 2352 && i[1] === 'banana' && i.length === 2,
i => i[1] i => i[1]
); );
@@ -24,7 +24,7 @@ describe('utils', () => {
it('should accept a function as a second parameter and use it as mapping function', () => { it('should accept a function as a second parameter and use it as mapping function', () => {
let sample = [[1235, 'hello'], [2352, 'banana']]; let sample = [[1235, 'hello'], [2352, 'banana']];
let fn = selectItem( let fn = select(
i => i[0] === 2352, i => i[0] === 2352,
i => i[1] i => i[1]
); );
@@ -36,14 +36,14 @@ describe('utils', () => {
it('should pass with one parameter', () => { it('should pass with one parameter', () => {
let sample = ['hello', 'lol', 'banana']; let sample = ['hello', 'lol', 'banana'];
let result = sample.reduce(selectItem(i => i === 'banana')); let result = sample.reduce(select(i => i === 'banana'));
result.should.be.equal('banana'); result.should.be.equal('banana');
}); });
it('should get a null in reduce result if reduce calls with second parameter that is null', () => { it('should get a null in reduce result if reduce calls with second parameter that is null', () => {
let sample = ['hello', 'lol', 'banana']; let sample = ['hello', 'lol', 'banana'];
let result = sample.reduce(selectItem(i => i === 'apple'), null); let result = sample.reduce(select(i => i === 'apple'), null);
should.not.exist(result); should.not.exist(result);
}); });
}); });