vanillaes / absurdum Goto Github PK
View Code? Open in Web Editor NEWThe Ridiculous Application of Reduce
License: MIT License
The Ridiculous Application of Reduce
License: MIT License
The inverse operation of Object.prototype.entries()
This takes an array of [property, value]
arrays and returns an object.
const.log(objects.fromEntries([['age', 12034], ['name', 'Trair'],['state', 'Floating']]));
> { age: 12034, name: 'Trair', state: 'Floating' }
In GitLab by @evanplaice on Jan 18, 2019, 23:07
CI testing makes eases the burden of collaboration.
The find() method returns the value of the first element in the provided array that satisfies the provided testing function.
var array1 = [5, 12, 8, 130, 44];
var found = array1.find(function(element) {
return element > 10;
});
console.log(found);
// expected output: 12
The current implementation flattens the output
Is this correct?
endsWith('abc', 'f')
returns true
should return false
returns true
Seems like code could be replaced with:
const endsWith = (string, substr = '') =>
string.substr(string.length - substr.length) === substr
Tap iterates through the values and applies a supplied function to each value without mutating the data.
Tap is an exception to the 'only use reduce' rule because reduce would add inefficiency.
Currently, this lib is written as ES+ with the dist files and tests being provided as CJS.
Now that Node.JS has experimental support for ESM (EcmaScript Modules), see if it's viable to run/develop/test the code natively in ES6.
Adds padding to the end of a string
Notice: The existing implementation doesn't match spec. Feel free to use it or trash it.
The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
Should this be implemented iteratively or recursively. Study the MDN documentation in more depth before implementing.
Filters an object by key to only include properties whitelisted by the second arg
To accomplish this, the object needs to be:
Due to the reliance on Object.entries() this function may not be compatible with some browsers.
Performs reduce on an array in reverse order (last->first)
some calls a function (the "test" function, defined by you) on each element of an array, and returns a boolean indicating whether or not the test function returned a truthy value for any element in the array. It "short circuits" as much computation as possible by terminating the array iteration as soon as an element is encountered for which the test function returns a truthy value
function gotMilk(array) {
return array.some((x) => x === 'milk');
}
gotMilk(['juice', 'water']); // false
gotMilk(['juice', 'milk', 'water']); // true
In GitLab by @evanplaice on Jan 18, 2019, 23:06
Find the index of the last item that matches or -1 if there is no match.
In GitLab by @evanplaice on Jan 18, 2019, 23:07
Add templates for the following
In GitLab by @evanplaice on Jan 18, 2019, 23:07
Update README with more detailed links to the operator descriptions
Takes an array of similar values and returns an object mapping each unique item to the number of items it occurs in the array.
Reference implementation
const input = ['a', 'b', 'a', 'c', 'a', 'c', 'b'];
const frequencies = input.reduce((acc, curr) => {
acc[curr] = !acc[curr] ? 1 : ++acc[curr];
return acc;
}, {});
console.log(frequencies);
> {
> a: 3,
> b: 2,
> c: 2
> }
Adds padding to the start of a string
In GitLab by @evanplaice on Jan 19, 2019, 00:20
This project is still pointing to the now closed GitHub page
Search a string to see if it ends with another string
The indexOf
method returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex. Returns -1 if the value is not found.
var paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?';
var searchTerm = 'dog';
var indexOfFirst = paragraph.indexOf(searchTerm);
console.log('The index of the first "' + searchTerm + '" from the beginning is ' + indexOfFirst);
// expected output: "The index of the first "dog" from the beginning is 40"
console.log('The index of the 2nd "' + searchTerm + '" is ' + paragraph.indexOf(searchTerm, (indexOfFirst + 1)));
// expected output: "The index of the 2nd "dog" is 52"
Reverses the input string
Takes an input string and reverses it's character order using reduce.
Flatten takes an array containing n-levels of nested arrays and flattens them into a one-dimensional array.
Should this be implemented iteratively or recursively. Study the lodash documentation in more depth before implementing.
The every() method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
It always returns true if the array is empty
function isBelowThreshold(currentValue) {
return currentValue < 40;
}
var array1 = [1, 30, 39, 29, 10, 13];
console.log(array1.every(isBelowThreshold));
// expected output: true
This project could benefit from a changelog. The commit history is pretty clean so the ideal solution would be to somehow add the capability to compile a list of changes using the commit titles and hand-edit out any extra crap.
Please comment below if you have any suggestions.
(Add Reference Links)
Gets all but the last element of a the array
In GitLab by @evanplaice on Jan 18, 2019, 23:07
Start mapping out the documentation structure
In GitLab by @evanplaice on Jan 19, 2019, 01:45
Make it so new versions are automatically published to NPM.
In GitLab by @evanplaice on Jan 19, 2019, 00:12
Make the existing templates work with GitLab and add missing templates
Breaks an array up into chunks of a specified size
The findIndex() method returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test.
var array1 = [5, 12, 8, 130, 44];
function isLargeNumber(element) {
return element > 13;
}
console.log(array1.findIndex(isLargeNumber));
// expected output: 3
The indexOf
method returns the first index at which a given element can be found in the array, or -1 if it is not present.
var beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];
console.log(beasts.indexOf('bison'));
// expected output: 1
// start from index 2
console.log(beasts.indexOf('bison', 2));
// expected output: 4
console.log(beasts.indexOf('giraffe'));
// expected output: -1
In GitLab by @evanplaice on Jan 20, 2019, 03:45
Extract the contributor instructions into a separate file. Remove old links to GitHub templates.
In GitLab by @evanplaice on Jan 19, 2019, 01:33
Update the CI badge to show the GitLab-CI status
Search a string to see if it includes another string
Fills a range of items in the array with a specified value.
Concetenate any number of arrays to any level of depth
In GitLab by @evanplaice on Jan 18, 2019, 23:57
Migrating from GitHub means Travis-CI is no longer an option.
Change the configuration to so this project runs CI through GitLab instead.
Find the difference between the input array and the included values
Creates a slice of an array with a specified number of items dropped from the start.
Filters an object by key to only include properties not blacklisted by the second arg
To accomplish this, the object needs to be:
Due to the reliance on Object.entries() this function may not be compatible with some browsers.
In GitLab by @evanplaice on Jan 18, 2019, 23:07
Creates a slice of an array with a specified number of items dropped from the start.
Creates an array of unique values that are included in all given arrays
One possible approach:
Use something like frequency then filter the results so only the values that have the frequency of input.length
are returned.
Repeats the input string a specified number of times
Takes a two-dimensional array, and a predicate. The two-dimensional array should contain two arrays of equal length. The values of each array are compared using the predicate.
Add code snippets and/or a more in-depth description of the implementation details
To quote the C#/Linq documentation for Zip:
The method merges each element of the first sequence with an element that has the same index in the second sequence. If the sequences do not have the same number of elements, the method merges sequences until it reaches the end of one of them. For example, if one sequence has three elements and the other one has four, the result sequence will have only three elements.
Filters all the falsy values (ie null, undefined, false, NaN, 0, "") out of an array.
Check to see if a string starts with another string.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.