4 ms·
Hmm? // extend Object.assign({}, { foo: 'bar' }, { baz: 'qui' }); // pluck [{ a:1, b:1 }, { a:2, b:2 }].map( obj => obj["a"] ) // f
by drinchev 10y ago
Hmm?
// extend
Object.assign({}, { foo: 'bar' }, { baz: 'qui' });
// pluck
[{ a:1, b:1 }, { a:2, b:2 }].map( obj => obj["a"] )
// filter obj
Object.keys(obj).reduce( ( result, key) => {
const value = obj[key];
if ( value < 6 ) {
result[key] = value
}
return value;
}, {})
// map obj
Object.keys(obj).reduce( ( result, key) => {
result[key] = obj[key] + 1;
return value;
}, {})
// template
const data = { a:1, b: { c: 1 }, d: 2 };
`some ${data.a}, ${data.b.c}`;
// unique
[1,2,2,3,4,4,5].filter( ( value, index, self ) => self.indexOf( value ) === index )
// last
[1,2,3].slice(-1)[0]
// union
[1,2,3,4].concat( [6,7,8,9] ).filter( ( value, index, self ) => self.indexOf( value ) === index ).sort( ( a,b ) => a-b )
- deleted 10y ago[deleted]
- minitech 10y agoIf you wrapped that "unique" implementation in some kind of reusable construct, it would be even easier to use, and it would be easy to replace with a more efficient implementation. Hmm.
- glial 10y agoThat's true, but you also increase your technical debt and decrease readability by people not familiar with the library.
- lexicality 10y agoI would cheerfully argue that repeating non obvious code that could easily be wrapped in a documented function with an obvious name raises technical debt considerably more than causing someone to briefly wonder what a function called 'unique' that operates on an array does.
- deleted 10y ago[deleted]