From dca671c564f53f9b57d200b39176af58cef8d56c Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 22 Feb 2016 04:36:22 +0300 Subject: [PATCH] rename common util selectItem -> select --- src/client/controllers/ScheduleController.js | 4 ++-- src/utils/common.js | 2 +- test/utils/common.js | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/client/controllers/ScheduleController.js b/src/client/controllers/ScheduleController.js index 7abd5e59..3a435303 100644 --- a/src/client/controllers/ScheduleController.js +++ b/src/client/controllers/ScheduleController.js @@ -1,7 +1,7 @@ import {populate} from '../../utils/populate'; import {getCourseNameByID} from '../../models/course'; import {indexEquals} from '../../utils/common'; -import {selectItem} from '../../utils/common'; +import {select} from '../../utils/common'; function isRequested(period, semester) { return function (schedule) { @@ -24,7 +24,7 @@ export default function (app) { schedules = schedules.map(schedule => { let sem = [['spring', 'Весена'], ['autumn', 'Осень']] - .reduce(selectItem( + .reduce(select( i => i[0] === schedule.semester, i => i[1] )); diff --git a/src/utils/common.js b/src/utils/common.js index 1c9ab200..798d0e43 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -39,6 +39,6 @@ export function indexEquals(withNumber) { * @param byCondition * @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) } \ No newline at end of file diff --git a/test/utils/common.js b/test/utils/common.js index d94bef14..db59b9f7 100644 --- a/test/utils/common.js +++ b/test/utils/common.js @@ -1,18 +1,18 @@ import should from 'should'; -import {selectItem} from '../../src/utils/common'; +import {select} from '../../src/utils/common'; describe('utils', () => { describe('common.js', () => { describe('selectItem', () => { it('should return a function', () => { - let fn = selectItem(); + let fn = select(); fn.should.be.type('function'); }); it('should accept a function as a first parameter and use it as byCondition', () => { let sample = [[1235, 'hello'], [2352, 'banana']]; - let fn = selectItem( + let fn = select( i => i[0] === 2352 && i[1] === 'banana' && i.length === 2, i => i[1] ); @@ -24,7 +24,7 @@ describe('utils', () => { it('should accept a function as a second parameter and use it as mapping function', () => { let sample = [[1235, 'hello'], [2352, 'banana']]; - let fn = selectItem( + let fn = select( i => i[0] === 2352, i => i[1] ); @@ -36,14 +36,14 @@ describe('utils', () => { it('should pass with one parameter', () => { 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'); }); it('should get a null in reduce result if reduce calls with second parameter that is null', () => { 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); }); });