Skip to content
Closed

2850 #2904

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions modules/_transition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export function getTogglingfunction() {
if (arguments.length == 0) {
function inner(input) {
return !input;
}
return inner;
} else if (arguments.length != 1) {
var args = arguments;
function inner(input){
let all_arguments = Array.from(args);
all_arguments_length = all_arguments.length;
index = all_arguments.indexOf(input);
return all_arguments[(index + 1) % all_arguments_length];
}
return inner
} else if (arguments[0] instanceof Array){
args = arguments[0];
function inner(input){
let all_arguments = args;
all_arguments_length = all_arguments.length;
index = all_arguments.indexOf(input);
return all_arguments[(index + 1) % all_arguments_length];
}
return inner
} else {
obj = arguments[0];
function inner(input) {
inner_obj = obj;
return inner_obj[input];
}
return inner
}
}
16 changes: 16 additions & 0 deletions modules/findkeys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import cb from './_cb.js';
import keys from './keys.js';


export default function findKeys(obj, predicate, context) {
predicate = cb(predicate, context);
var _keys = keys(obj), key;
var arr = [];
for (var i = 0, length = _keys.length; i < length; i++) {
key = _keys[i];
if (predicate(obj[key], key, obj)) {
arr.push(key);
}
}
return arr;
}
1 change: 1 addition & 0 deletions modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export { default as result } from './result.js';
export { default as uniqueId } from './uniqueId.js';
export { default as chain } from './chain.js';
export { default as iteratee } from './iteratee.js';
export { default as findKeys } from './findkeys.js';

// Function (ahem) Functions
// -------------------------
Expand Down
8 changes: 8 additions & 0 deletions test/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,12 @@
assert.strictEqual(template(), '<<\nx\n>>');
});

QUnit.test('findkeys - extended findkey function.', function(assert) {
input = {'a':2, 'b':2}
var key = _.findKey(info, function (value) {
return value === 2;
});
assert.strictEqual(_.findKeys(input, ['a', 'b']))
});

}());