Sorting by alphabetical order immutable.js

I would like to sort immutable.js orderedList by property name,

data.map(x => x.get("name")) returns the string, I want to sort my map by name in alphabetical order.

How to do that? I tried:

return data.sortBy((val) => {
    if (dir === "up") {
      return val.get("name");
    } else {
      return - val.get("name");
    }
  });

Answers


var fiends = Immutable.fromJS([{name: 'Squirrel'}, {name: 'Cat'}, {name: 'Raccoon'}]);
var sorted = fiends.sortBy(
  (f) => f.get('name')
);
sorted.map(x => x.get('name')).toJS();  // ["Cat", "Raccoon", "Squirrel"]

With localCompare:

fiends.sort(
  (a, b) => a.get('name').localeCompare(b.get('name'))
);

Need Your Help

Conditional Statements in PHP code Between HTML Code

php html conditional-statements

I'm having a bit of an issue by using Conditional Statements in PHP separated by HTML code. This is the type of code I'm trying to write. This is a profile page and it should only be seen by the user

override jquery validate plugin email address validation

jquery regex jquery-validate email-validation

I find that jQuery validation plugin regex to be insufficient for my requirement. It accepts any email address xxx@hotmail.x as a valid email address whereas I want to be able to supply this regex ...