Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Subtracting Numbers in Array

const numbers = [1800, 50, 300, 20, 100];

// subtract all numbers from first number
// since 1st element is called as accumulator rather than currentValue
// 1800 - 50 - 300 - 20 - 100
let difference = numbers.reduce(
  (accumulator, currentValue) => accumulator - currentValue
);
console.log(difference); // 1330

const expenses = [1800, 2000, 3000, 5000, 500];
const salary = 15000;

// function that subtracts all array elements from given number
// 15000 - 1800 - 2000 - 3000 - 5000 - 500
let remaining = expenses.reduce(
  (accumulator, currentValue) => accumulator - currentValue,
  salary
);
console.log(remaining); // 2700
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to send Flutter Color as json || convert String to Color Flutter 
Javascript :: this ....object of. 
Javascript :: convert java object to json 
Javascript :: what is render in react native 
Javascript :: lavania 
Javascript :: visable in viewport 
Javascript :: Parents, Children & Siblings 
Javascript :: react native red Triangle Left 
Javascript :: find duplicate objects in array js 
Javascript :: javascrpt 
Javascript :: easyui datagrid scrollto 
Javascript :: javascript update page when json file changes 
Javascript :: Safe Area View for android / Removing overflow of screen for android 
Javascript :: how to prevent todos from vanishing after refreshing page - javascript 
Javascript :: node fs stream pipe promise 
Javascript :: for loop shothand in js 
Javascript :: react 1 to 10 rating 
Javascript :: joomla add javascript 
Javascript :: makestyle server side rendering 
Javascript :: disable find in page chrome through javascript 
Javascript :: how to rmeove white space in a string with jquery 
Javascript :: parse int stackoverflow 
Javascript :: formatDuration js 
Javascript :: form react js 
Javascript :: javascript perms 
Javascript :: firebase js loop 
Javascript :: jquery timeout 
Javascript :: check variable is array or not in javascript 
Javascript :: how to use props data inside setup 
Javascript :: change active menu item on page scroll javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =