Skip to content

Instantly share code, notes, and snippets.

@rcdexta
rcdexta / every.js
Created March 28, 2019 04:48
every function
const elements = ["cat", "dog", "bat"]
_.every(elements, el => el.length == 3)
elements.every(el => el.length == 3) //true
@rcdexta
rcdexta / each.js
Created March 28, 2019 03:12
iterate array
_.each([1, 2, 3], (value, index) => {
console.log(value)
})
[1, 2, 3].forEach((value, index) => {
console.log(value)
})
_.forEach({ 'a': 1, 'b': 2 }, (value, key) => {
console.log(key);
@rcdexta
rcdexta / reverse.js
Last active March 28, 2019 03:06
reversing array
const array = ['a', 'b', 'c']
console.log(_.reverse(array)) // output: ['c', 'b', 'a']
// Native
const array = ['a', 'b', 'c']
array.reverse()
console.log(array) // output: ['c', 'b', 'a']
@rcdexta
rcdexta / first_rest.js
Created March 28, 2019 02:59
first and rest
const names = ["first", "middle", "last", "suffix"]
const firstName = _.first(names)
const otherNames = _.rest(names)
const [firstName, ...otherNames] = names
console.log(firstName) // 'first'
console.log(otherNames) // [ 'middle', 'last', 'suffix' ]
@rcdexta
rcdexta / filter.js
Last active March 28, 2019 03:06
_.filter vs array.filter
const numbers = [10, 40, 230, 15, 18, 51, 1221]
_.filter(numbers, num => num % 3 === 0)
numbers.filter(num => num % 3 === 0)
@rcdexta
rcdexta / find.js
Last active April 12, 2019 23:44
_.find vs native find
const users = [
{ 'user': 'joey', 'age': 32 },
{ 'user': 'ross', 'age': 41 },
{ 'user': 'chandler', 'age': 39 }
]
// Native
users.find(function (o) { return o.age < 40; })
//lodash
<blockquote>
There is <del>nothing</del> <ins>no code</ins> either good or bad, but <del>thinking</del> <ins>running it</ins> makes it so.
</blockquote>
<video controls>
<source src="https://addpipe.com/sample_vid/short.mp4"
poster="https://addpipe.com/sample_vid/poster.png">
Sorry, your browser doesn't support embedded videos.
</video>
<label for="date">Enter date:</label>
<input type="date" id="date"/>
<label for="datetime">Enter date & time:</label>
<input type="datetime-local" id="datetime"/>
<label for="month">Enter month:</label>
<input type="month" id="month"/>
<label for="search">Search for:</label>
<label for="upload">Upload progress:</label>
<meter id="upload" name="upload"
min="0" max="100"
low="33" high="66" optimum="80"
value="50">
at 50/100
</meter>
<hr/>