Published
- 1 min read
javascript sort boolean value
The solution for this is noted below
javascript sort boolean value
Solution
a = [
false,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
false,
true,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false
]
a.sort(function (x, y) {
// true values first
return x === y ? 0 : x ? -1 : 1
// false values first
// return (x === y)? 0 : x? 1 : -1;
})
console.log(a)
Try other methods by searching on the site. That is if this doesn’t work