ive

Home cooks in Thiruvananthapuram are championing artificial additive-free jams, preserves, juice, ethnic eats and more

Four home cooks in Thiruvananthapuram are turning fruits into value-added products without using artificial flavours or preservatives




ive

Collective memory as currency [electronic resource] : the dominance of the past in the present / Tracy Adams.

Berlin ; Boston : De Gruyter [2024]




ive

Plastic is fantastic: Credit cards register highest growth in five years

Axis Bank leads charge, SBI narrows gap with ICICI, HDFC Bank on top; numbers inch up to 25m




ive

India among top five innovation destinations: report




ive

Sensex jumps 430 points in early trade on positive global trends

The NSE Nifty climbed 138.80 points.




ive

Markets give up initial gains dragged by sharp fall in Kotak Bank, unabated foreign fund outflows

Equity markets open strong but later decline; HDFC Bank gains, Kotak Mahindra Bank falls, global markets mixed




ive

Markets fall dragged by Hindustan Unilever; massive foreign fund outflows

Nestle, Bharti Airtel, Bajaj Finserv, ICICI Bank and Maruti were the other big laggards




ive

New bridge to come up across Palar River at Sevilimedu




ive

Three engineering students drown in Cauvery river in Namakkal

Jedarpalayam police registered a case and are investigating




ive

Police women under the ‘Police Akka’ initiative, to reach out to schoolgirls in Pudukottai district

Policewomen nominated under this initiative will visit schools and colleges every 15 days to ascertain concerns and grievances of students and render assistance




ive

Five-day special educator training programme to start from November 11

The initiative is being organised by Chennai Volunteers, a social initiative of the Giving Matters Foundation, a not-for-profit organisation, in collaboration with the Portobello Institute, Ireland




ive

Mediation should be given priority in family dispute cases: Chief Justice




ive

Deputy Chief Minister launches initiatives to support start-up ecosystem in T.N.

He also presents sanction letters for pre-incubation centres, which aim to support innovative business ideas in their initial stages




ive

Organic/inorganic heterostructures templated by interfacial instability-driven BCP colloids in deformable emulsion droplets

Soft Matter, 2024, 20,8174-8180
DOI: 10.1039/D4SM00921E, Communication
Yuqing Song, Nan Yan, Lingli Wan, Jingjing Li, Ye Gao
Core–shell colloids are self-assembled in emulsion droplets driven by interfacial instability, which serve as excellent scaffolds for designing organic/inorganic heterostructures.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Effective patchiness from critical points of a coarse-grained protein model with explicit shape and charge anisotropy

Soft Matter, 2024, 20,8455-8467
DOI: 10.1039/D4SM00867G, Paper
Open Access
  This article is licensed under a Creative Commons Attribution 3.0 Unported Licence.
Jens Weimar, Frank Hirschmann, Martin Oettel
Critical points of an anisotropic, coarse-grained protein model are used to detemine an “effective patchiness” by comparison to the Kern–Frenkel patchy model.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Segregative phase separation of strong polyelectrolyte complexes at high salt and high polymer concentrations

Soft Matter, 2024, 20,8505-8514
DOI: 10.1039/D4SM00994K, Paper
Open Access
  This article is licensed under a Creative Commons Attribution 3.0 Unported Licence.
Conner H. Chee, Rotem Benharush, Lexi R. Knight, Jennifer E. Laaser
Complexes of strong polyelectrolytes prepared well above the binodal are shown to undergo hydrophobicity-driven segregative phase separation.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Optimality and cooperativity in superselective surface binding by multivalent DNA nanostars

Soft Matter, 2024, 20,8515-8523
DOI: 10.1039/D4SM00704B, Paper
Open Access
  This article is licensed under a Creative Commons Attribution 3.0 Unported Licence.
Christine Linne, Eva Heemskerk, Jos W. Zwanikken, Daniela J. Kraft, Liedewij Laan
Our study shows that DNA nanostars with three binding sites (ligands) can (1) bind superselectively to surfaces based on receptor density, and (2) that interactions between ligands affect the optimum number of ligands required for superselectivity.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

pH and glucose dual-responsive phenylboronic acid hydrogels for smart insulin delivery

Soft Matter, 2024, Advance Article
DOI: 10.1039/D4SM01004C, Paper
Keke Yang, Hou Bo, Dewei Ma, Mingwei Peng, Qinglong Liu, Ziwen Heng, Zhongwei Gu, Xuhan Liu, Siyuan Chen
Phenylboronic acid (PBA) is a widely exploited glucose-sensitive element for constructing glucose-responsive hydrogels to enable smart insulin delivery.
To cite this article before page numbers are assigned, use the DOI form of citation above.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Jamming crossovers in a confined driven polymer in solution

Soft Matter, 2024, Advance Article
DOI: 10.1039/D4SM00761A, Paper
Setarehalsadat Changizrezaei, Mikko Karttunen, Colin Denniston
A polymer confined in a nanochannel undergoes a crossover to a jammed state when pushed by a large spherical colloid. We examine the system using simulations that incorporate the full hydrodynamic driving and fluctuating forces.
To cite this article before page numbers are assigned, use the DOI form of citation above.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Src kinase slows collective rotation of confined epithelial cell monolayers

Soft Matter, 2024, Accepted Manuscript
DOI: 10.1039/D4SM00827H, Paper
Nastassia Pricoupenko, Flavia Marsigliesi, Philippe Marcq, Carles Blanch-Mercader, Isabelle A Bonnet
Collective cell migration is key during development, wound healing and metastasis and relies on coordinated cell behaviors at the group level. Src kinase is a key signalling protein for physiological...
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Long-lived unidirectional flow of active particles within long narrow channels

Soft Matter, 2024, Advance Article
DOI: 10.1039/D4SM00879K, Paper
Man Xu, Ying Lan, Yuehua Yang, Hongyuan Jiang
We present the dynamics of particles in a device divided into two chambers by V-shaped barriers and connected by a narrow channel. Here three distinct movement modes occur, including stochastic movement, oscillation and unidirectional flows.
To cite this article before page numbers are assigned, use the DOI form of citation above.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Mapping deformation dynamics to composition of topologically-active DNA blends

Soft Matter, 2024, Advance Article
DOI: 10.1039/D4SM01065E, Paper
Karthik R. Peddireddy, Ryan McGorty, Rae M. Robertson-Anderson
We leverage in situ enzymatic topological conversion and OpTiDDM to map the deformation dynamics of DNA blends with over 70 fractions of linear, ring and supercoiled molecules that span the phase space of possible topological compositions.
To cite this article before page numbers are assigned, use the DOI form of citation above.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Towards a universal model for the foaming behavior of surfactants: a case study on per- and polyfluoroalkyl substances (PFAS)

Soft Matter, 2024, Advance Article
DOI: 10.1039/D4SM00931B, Paper
Muchu Zhou, Reza Foudazi
Foam fractionation offers a promising solution for the separation of surface-active contaminants from water.
To cite this article before page numbers are assigned, use the DOI form of citation above.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Active nematic coherence probed under spatial patterns of distributed activity

Soft Matter, 2024, Accepted Manuscript
DOI: 10.1039/D4SM00651H, Paper
Ignasi Vélez Cerón, Jordi Ignes-Mullol, Francesc Sagues
A photoresponsive variant of the paradigmatic active nematic fluid made of microtubules and powered by kinesin motors is studied in the conventional two-dimensional interfaced form when forced under blue-light illumination....
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Banana DNA derivatives as homeotropic alignment layers in optical devices

Soft Matter, 2024, 20,8561-8569
DOI: 10.1039/D4SM00322E, Paper
Rafał Węgłowski, Anna Spadło, Dorota Węgłowska
In this study, DNA extracted from bananas was functionalized and used as a homeotropic alignment layer for liquid crystals.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Dynamical crossovers and correlations in a harmonic chain of active particles

Soft Matter, 2024, 20,8638-8653
DOI: 10.1039/D4SM00350K, Paper
Subhajit Paul, Abhishek Dhar, Debasish Chaudhuri
We explore the dynamics of a tracer in a harmonic chain of active particles, investigating the influence of interactions. Depending upon the time-scales governed by the interaction and the persistence of activity, we explore crossovers between different scaling behaviors of its dynamics.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Model predictive control of non-interacting active Brownian particles

Soft Matter, 2024, 20,8581-8588
DOI: 10.1039/D4SM00902A, Paper
Titus Quah, Kevin J. Modica, James B. Rawlings, Sho C. Takatori
Model predictive control is used to guide the spatiotemporal distribution of active Brownian particles by forecasting future states and optimizing control inputs to achieve tasks like dividing a population into two groups.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Tuning collective actuation of active solids by optimizing activity localization

Soft Matter, 2024, 20,8570-8580
DOI: 10.1039/D4SM00868E, Paper
Davi Lazzari, Olivier Dauchot, Carolina Brito
Active solids, more specifically elastic lattices embedded with polar active units, exhibit collective actuation when the elasto-active feedback, generically present in such systems, exceeds some critical value.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Pickering emulsions for stimuli-responsive transdermal drug delivery: effect of rheology and microstructure on performance

Soft Matter, 2024, 20,8621-8637
DOI: 10.1039/D4SM00993B, Paper
Open Access
  This article is licensed under a Creative Commons Attribution 3.0 Unported Licence.
Simona Migliozzi, Yiting He, Maryam Parhizkar, Yang Lan, Panagiota Angeli
Elucidating the impact of microgels attributes on the microstructure, rheology and functionality of Pickering emulsions.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Entropically and enthalpically driven self-assembly of a naphthalimide-based luminescent organic π-amphiphile in water

Soft Matter, 2024, 20,8684-8691
DOI: 10.1039/D4SM00986J, Paper
Sk Mursed Ali, Sujauddin Sk, Shuvajyoti Sarkar, Sayani Das, Nayim Sepay, Mijanur Rahaman Molla
Entropically and enthalpically favourable vesicular self-assembly of a naphthalimide based water soluble luminescent organic dipolar building block is reported.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Bending of polymer films: a method for obtaining a compressive modulus of thin films

Soft Matter, 2024, 20,8589-8600
DOI: 10.1039/D4SM00084F, Paper
Akihiro Ohara, Ko Okumura
We constructed a theory and method for measuring the compressive modulus by combining tensile and bending tests. Elastic asymmetry was confirmed in an industrial PET film.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Light scattering study of algal floc growth and structure: alum vs. polymeric plant-derived flocculant

Soft Matter, 2024, Advance Article
DOI: 10.1039/D4SM00837E, Paper
Temitope Orimolade, Ngoc-Tram Le, Lyle Trimble, Bandaru Ramarao, Sitaraman Krishnan
Algal flocculation using alum shows dynamic fractal restructuring over time, while Moringa oleifera protein induces faster densification, enhancing floc strength.
To cite this article before page numbers are assigned, use the DOI form of citation above.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Hydrogel-based 3D fabrication of multiple replicas with varying sizes and materials from a single template via iterative shrinking

Soft Matter, 2024, Accepted Manuscript
DOI: 10.1039/D4SM00835A, Paper
Eunseok Heo, Hye Been Koo, Jun Chang Yang, In Cho, Hyun-Hee Lee, Yong-Jin Yoon, Steve Park, Jae-Byum Chang
3D printing technologies have been widely used for the rapid prototyping of 3D structures, but their application in a broader context has been hampered by their low printing throughput. For...
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Understanding Polymer-Colloid Gels: A Solvent Perspective Using Low-Field NMR

Soft Matter, 2024, Accepted Manuscript
DOI: 10.1039/D4SM01098A, Communication
Léo Hervéou, Gauthier Legrand, Thibaut Divoux, Guilhem Pablo Baeza
The present work emphasizes the relevance of low-field NMR relaxometry to investigate colloid-polymer hydrogels by probing water dynamics across a wide range of formulations between 10°C and 80°C. By examining...
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Dynamics of switching processes: general results and applications to intermittent active motion

Soft Matter, 2024, Accepted Manuscript
DOI: 10.1039/D4SM01054J, Paper
Open Access
  This article is licensed under a Creative Commons Attribution 3.0 Unported Licence.
Ion Santra, Deepak Gupta, Kristian S Olsen
Systems switching between different dynamical phases is an ubiquitous phenomenon. The general understanding of such a process is limited. To this end, we present a general expression that captures fluctuations...
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Reversible pH-responsive supramolecular aggregates from viologen based amphiphiles – A molecular design perspective

Soft Matter, 2024, Accepted Manuscript
DOI: 10.1039/D4SM00695J, Paper
Redhills L. Narendran, Archita Patnaik
pH responsive self-assembled supramolecular systems in water hold tremendous promise spanning across the various realms of science and technology. Herein, we report the design and synthesis of benzyl viologen (BV)...
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Obstacle-enhanced spontaneous oscillation of confined active granules

Soft Matter, 2024, Advance Article
DOI: 10.1039/D4SM01027B, Paper
Xue Zhang, Yuxin Tian, Ran Ni, Yong Zhu, Luhui Ning, Peng Liu, Mingcheng Yang, Ning Zheng
Obstacle-enhanced spontaneous oscillation of confined active granules. (a) Without obstacles. (b) With obstacles.
To cite this article before page numbers are assigned, use the DOI form of citation above.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Biomimetic mineralization of positively charged silica nanoparticles templated by thermoresponsive protein micelles: applications to electrostatic assembly of hierarchical and composite superstructures

Soft Matter, 2024, Advance Article
DOI: 10.1039/D4SM00907J, Paper
Nada Y. Naser, William C. Wixson, Helen Larson, Brandi M. Cossairt, Lilo D. Pozzo, François Baneyx
Exploiting the ability of a solid-binding elastin-like peptide to micellize, we mineralize monodisperse silica nanoparticles whose positive surface charge enables one-step electrostatic assembly of various mono- and bi-material superstructures.
To cite this article before page numbers are assigned, use the DOI form of citation above.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Individual Closed-Loop Control of Micromotors by Selective Light Actuation

Soft Matter, 2024, Accepted Manuscript
DOI: 10.1039/D4SM00810C, Communication
Open Access
David Rivas, Max Sokolich, Sambeeta Das
Control of individual micromotors within a group would allow for improved efficiency, greater ability to accomplish complex tasks, higher throughput, and increased adaptability. However, independent control of micromotors remains a...
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Coarsening dynamics of aster defects in a model polar active matter

Soft Matter, 2024, Accepted Manuscript
DOI: 10.1039/D4SM00788C, Paper
Soumyadeep Mondal, Pankaj Popli, Sumantra Sarkar
We numerically study the dynamics of topological defects in 2D polar active matter coupled to a conserved density field, which shows anomalous kinetics and defect distribution. The initial many- defect...
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Shape transformations in peptide-DNA coacervates driven by enzyme-catalyzed deacetylation

Soft Matter, 2024, Accepted Manuscript
DOI: 10.1039/D4SM01091D, Paper
Open Access
Merlijn van Haren, Nienke Helmers, Luuk Verploegen, Viveca Beckers, Evan Spruijt
Biomolecular condensates formed by liquid-liquid phase separation (LLPS) are important organizers of biochemistry in living cells. Condensate formation can be dynamically regulated, for example by protein binding or enzymatic processes....
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Percolation transitions in a binary mixture of active Brownian particles with different softness

Soft Matter, 2024, Advance Article
DOI: 10.1039/D4SM00981A, Paper
Monika Sanoria, Raghunath Chelakkot, Amitabha Nandi
Homogeneous active Brownian particle (ABP) systems with purely repulsive interactions are considered to exhibit a simple phase behavior, but various physical attributes of active entities can lead to variation in the collective dynamics.
To cite this article before page numbers are assigned, use the DOI form of citation above.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

The influence of active agent motility on SIRS epidemiological dynamics

Soft Matter, 2024, Advance Article
DOI: 10.1039/D4SM00864B, Paper
Open Access
R. Kailasham, Aditya S. Khair
Motility induced phase separation of active disks with SIRS epidemiological dynamics.
To cite this article before page numbers are assigned, use the DOI form of citation above.
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Effects of Hydration Water on Bioresponsiveness of Polymer Interfaces Revealed by Analysis of Linear and Cyclic Polymer–Grafted Substrates

Soft Matter, 2024, Accepted Manuscript
DOI: 10.1039/D4SM00977K, Paper
Open Access
Shin-nosuke Nishimura, Naoya Kurahashi, Shohei Shiomoto, Yoshihisa Harada, Masaru Tanaka
Given that the hydration water of polymer matrices may differ from that of outermost polymer surfaces, processes at biomaterial–biofluid interfaces and role of hydration water therein cannot be adequately examined...
The content of this RSS Feed (c) The Royal Society of Chemistry




ive

Five Interesting Ways to Use Array.reduce() (And One Boring Way)

Chris Ferdinandi turns the heat down low and lets the sauce reduce while we take a look at how to add spice to our source with a sprinkling of Array.reduce(). Just a little ingenuity with the humblest of functions.


Of all the modern array methods, the one I had the hardest time wrapping my head around was Array.reduce().

On the surface, it seems like a simple, boring method that doesn’t do much. But below its humble exterior, Array.reduce() is actually a powerful, flexible addition to your developer toolkit.

Today, we’re going to look at some cool things you can do with Array.reduce().

How Array.reduce() works

Most of the modern array methods return a new array. The Array.reduce() method is a bit more flexible. It can return anything. Its purpose is to take an array and condense its content into a single value.

That value can be a number, a string, or even an object or new array. That’s the part that’s always tripped me up – I didn’t realize just how flexible it is!

The syntax

The Array.reduce() accepts two arguments: a callback method to run against each item in the array, and a starting value.

The callback also accepts two arguments: the accumulator, which is the current combined value, and the current item in the loop. Whatever you return is used as the accumulator for the next item in the loop. On the very first loop, that starting value is used instead.

var myNewArray = [].reduce(function (accumulator, current) {
  return accumulator;
}, starting);

Let’s look at some examples to make this all tangible.

1. Adding numbers together

Let’s say you had an array of numbers that you wanted to add together. Using Array.forEach(), you might do something like this:

var total = 0;

[1, 2, 3].forEach(function (num) {
  total += num;
});

This is the cliche example for using Array.reduce(). I find the word accumulator confusing, so in this example, I’m calling it sum, because that’s what it is.

var total = [1, 2, 3].reduce(function (sum, current) {
  return sum + current;
}, 0);

Here, we pass in 0 as our starting value.

In the callback, we add the current value to the sum, which has our starting value of 0 on the first loop, then 1 (the starting value of 0 plus the item value of 1), then 3 (the sum value of 1 plus the item value of 2), and so on.

Here’s a demo.

2. Combining multiple array methods into Array.map() and Array.filter() into a single step

Imagine you had an array of wizards at Hogwarts.

var wizards = [
  {
    name: 'Harry Potter',
    house: 'Gryfindor'
  },
  {
    name: 'Cedric Diggory',
    house: 'Hufflepuff'
  },
  {
    name: 'Tonks',
    house: 'Hufflepuff'
  },
  {
    name: 'Ronald Weasley',
    house: 'Gryfindor'
  },
  {
    name: 'Hermione Granger',
    house: 'Gryfindor'
  }
];

You want to create a new array that contains just the names of wizards who are in Hufflepuff. One way you could do that is by using the Array.filter() method to get back just wizards whose house property is Hufflepuff. Then, you’d use the Array.map() method to create a new array containing just the name property for the remaining wizards.

// Get the names of the wizards in Hufflepuff
var hufflepuff = wizards.filter(function (wizard) {
  return wizard.house === 'Hufflepuff';
}).map(function (wizard) {
  return wizard.name;
});

With the Array.reduce() method, we can get the same array in a single pass, improving our performance. You pass in an empty array ([]) as the starting value. On each pass, you check to see if the wizard.house is Hufflepuff. If it is, you push it to the newArr (our accumulator in this example). If not, you do nothing.

Either way, you return the newArr to become the accumulator on the next pass.

// Get the names of the wizards in Hufflepuff
var hufflepuff = wizards.reduce(function (newArr, wizard) {
  if (wizard.house === 'Hufflepuff') {
    newArr.push(wizard.name);
  }
  return newArr;
}, []);

Here’s another demo.

3. Creating markup from an array

What if, instead of creating an array of names, we wanted to create an unordered list of wizards in Hufflepuff? Instead of passing an empty array into Array.reduce() as our starting value, we’ll pass in an empty string ('') and call it html.

If the wizard.house equals Hufflepuff, we’ll concatenate our html string with the wizard.name wrapped in an opening and closing list item (li). Then, we’ll return the html to become the accumulator on the next loop.

// Create a list of wizards in Hufflepuff
var hufflepuffList = wizards.reduce(function (html, wizard) {
  if (wizard.house === 'Hufflepuff') {
    html += '<li>' + wizard.name + '</li>';
  }
  return html;
}, '');

Add an opening and closing unordered list element before and after Array.reduce(), and you’re ready to inject your markup string into the DOM.

// Create a list of wizards in Hufflepuff
var hufflepuffList = '<ul>' + wizards.reduce(function (html, wizard) {
  if (wizard.house === 'Hufflepuff') {
    html += '<li>' + wizard.name + '</li>';
  }
  return html;
}, '') + '</ul>';

See it in action here.

4. Grouping similar items in an array together

The lodash library has a groupBy() method takes a collection of items as an array and groups them together into an object based on some criteria.

Let’s say you want an array of numbers.

If you wanted to group all of the items in numbers together based on their integer value, you would do this with lodash.

var numbers = [6.1, 4.2, 6.3];

// returns {'4': [4.2], '6': [6.1, 6.3]}
_.groupBy(numbers, Math.floor);

If you had an array of words, and you wanted to group the items in words by their length, you would do this.

var words = ['one', 'two', 'three'];

// returns {'3': ['one', 'two'], '5': ['three']}
_.groupBy(words, 'length');

Creating a groupBy() function with Array.reduce()

You can recreate that same functionality using the Array.reduce() method.

We’ll create a helper function, groupBy(), that accepts the array and criteria to sort by as arguments. Inside groupBy(), we’ll run Array.reduce() on our array, passing in an empty object ({}) as our starting point, and return the result.

var groupBy = function (arr, criteria) {
  return arr.reduce(function (obj, item) {
    // Some code will go here...
  }, {});
};

Inside the Array.reduce() callback function, we’ll check to see if the criteria is a function, or a property of the item. Then we’ll get its value from the current item.

If there’s no property in the obj with that value yet, we’ll create it and assign an empty array as its value. Finally, we’ll push the item to that key, and return the object as the accumulator for the next loop.

var groupBy = function (arr, criteria) {
  return arr.reduce(function (obj, item) {

    // Check if the criteria is a function to run on the item or a property of it
    var key = typeof criteria === 'function' ? criteria(item) : item[criteria];

    // If the key doesn't exist yet, create it
    if (!obj.hasOwnProperty(key)) {
      obj[key] = [];
    }

    // Push the value to the object
    obj[key].push(item);

    // Return the object to the next item in the loop
    return obj;

  }, {});
};

Here’s a demo of the completed helper function.

Special thanks to Tom Bremer for helping me make some improvements to this one. You can find this helper function and more like it on the Vanilla JS Toolkit.

5. Combining data from two sources into an array

Remember our array of wizards?

var wizards = [
  {
    name: 'Harry Potter',
    house: 'Gryfindor'
  },
  {
    name: 'Cedric Diggory',
    house: 'Hufflepuff'
  },
  {
    name: 'Tonks',
    house: 'Hufflepuff'
  },
  {
    name: 'Ronald Weasley',
    house: 'Gryfindor'
  },
  {
    name: 'Hermione Granger',
    house: 'Gryfindor'
  }
];

What if you had another data set, an object of house points each wizard has earned.

var points = {
  HarryPotter: 500,
  CedricDiggory: 750,
  RonaldWeasley: 100,
  HermioneGranger: 1270
};

Imagine you wanted to combine both sets of data into a single array, with the number of points added to each wizard’s data in the wizards array. How would you do it?

The Array.reduce() method is perfect for this!

var wizardsWithPoints = wizards.reduce(function (arr, wizard) {

  // Get the key for the points object by removing spaces from the wizard's name
  var key = wizard.name.replace(' ', '');

  // If the wizard has points, add them
  // Otherwise, set them to 0
  if (points[key]) {
    wizard.points = points[key];
  } else {
    wizard.points = 0;
  }

  // Push the wizard object to the new array
  arr.push(wizard);

  // Return the array
  return arr;

}, []);

Here’s a demo combining data from two sources into an array.

6. Combining data from two sources into an object

What if you instead wanted to combine the two data sources into an object, where each wizard’s name was the key, and their house and points were properties? Again, the Array.reduce() method is perfect for this.

var wizardsAsAnObject = wizards.reduce(function (obj, wizard) {

  // Get the key for the points object by removing spaces from the wizard's name
  var key = wizard.name.replace(' ', '');

  // If the wizard has points, add them
  // Otherwise, set them to 0
  if (points[key]) {
    wizard.points = points[key];
  } else {
    wizard.points = 0;
  }

  // Remove the name property
  delete wizard.name;

  // Add wizard data to the new object
  obj[key] = wizard;

  // Return the array
  return obj;

}, {});

Here’s a demo combining two data sets into an object.

Should you use Array.reduce() more?

The Array.reduce() method has gone from being something I thought was pointless to my favorite JavaScript method. So, should you use it? And when?

The Array.reduce() method has fantastic browser support. It works in all modern browsers, and IE9 and above. It’s been supported in mobile browsers for a long time, too. If you need to go back even further than that, you can add a polyfill to push support back to IE6.

The biggest complaint you can make about Array.reduce() is that it’s confusing for people who have never encountered it before. Combining Array.filter() with Array.map() is slower to run and involves extra steps, but it’s easier to read. It’s obvious from the names of the methods what they’re supposed to be doing.

That said, there are times where Array.reduce() makes things that would be complicated more simple rather than more complicated. The groupBy() helper function is a good example.

Ultimately, this is another tool to add to your toolkit. A tool that, if used right, can give you super powers.


About the author

Chris Ferdinandi helps people learn vanilla JavaScript. He believes there’s a simpler, more resilient way to make things for the web.

Chris is the author of the Vanilla JS Pocket Guide series, creator of the Vanilla JS Academy training program, and host of the Vanilla JS Podcast. His developer tips newsletter is read by thousands of developers each weekday.

He’s taught developers at organizations like Chobani and the Boston Globe, and his JavaScript plugins have been used used by Apple and Harvard Business School. Chris Coyier, the founder of CSS-Tricks and CodePen, has described his writing as “infinitely quote-worthy.”

Chris loves pirates, puppies, and Pixar movies, and lives near horse farms in rural Massachusetts. He runs Go Make Things with Bailey Puppy, a lab-mix from Tennessee.

More articles by Chris




ive

Celebspotting: Lakme Fashion Week Winter/Festive 2016

Who modelled for whom during this year's edition of Lakme Fashion Week's Winter collection?




ive

Bending fashion the cheapensive way

Creating a balance between budget and fashion, branded and streetwear, reuse and recycle, Bengaluru's college goers show the way




ive

Onam weaves for 2022 comes alive with blooms and Kerala-themed motifs

Designers dress up the traditional cream-and-gold Kerala cotton with hand-painted motifs, embroidery, cut work and more




ive

For the festive season, designers are working with artisans to create clothes with a conscience

As gifting and dressing up for the festive season begins, consumers are increasingly looking at sustainable, environment friendly choices



  • Life &amp; Style

ive

Has the Congress already given up?