Array Helpers
var numbers = [1, 2, 3, 4, 5]
Array.prototype.square = function(){ return this.map(num => num ** 2) }
Array.prototype.cube = function(){ return this.map(num => num ** 3) }
Array.prototype.sum = function(){ return this.reduce((acc, curr) => acc + curr , 0) }
Array.prototype.average = function(){
return this.reduce((acc, curr) => acc + curr , 0) / this.length
}
Array.prototype.even = function(){ return this.filter(num => num % 2 === 0) }
Array.prototype.odd = function(){ return this.filter(num => num % 2 !== 0) }
console.log(numbers.square())
Also in JavaScript:
- javascript leave page warning
- public static void main(dsjjsdds, jdnjd, jsndjsd, isjdjsd, sjdijs, skjdks_+) __ osakd___ +++
- bootstrap show modal jquery
- jquery onchange input value
- smtpjs download
- puppeteer event element change
- capacitor.ionicframework.com to apk
- json identifier with period
- angular size of array
- jquery modal on show + target button
- how to create instance of class in javascript
- nodejs connection to localhost refused mysql errno -61
- short string javascript
- check if element is visible
- how to add multiple styles in javascript
- scroll to top
- javascript get multiple elements by id
- react get data attribute from element
- ad data to js object
- price range slider bootstrap 4
- javascript boolean
- js selection box excel node
- v-switch vuex store
- single node elasticsearch with enable security basic in docker