Reputation: 47
Using JavaScript, I want to reduce a string to include characters within ASCII 65-90 only (uppercase letters from A-Z).
My function starts with turning the string into full uppercase. Spaces are eliminated next and finally, letters are converted to ASCII decimals.
I want letters A-Z only (ASCII 65-90), nothing else. What if the string, however, does contain one or more non-desired characters? Is there a way to eliminate all instances of characters <
ASCII 65 and >
ASCII 90 from a string?
Upvotes: 1
Views: 58
Reputation: 30685
You could use a simple reduce call:
const input = "asddgAeBcc6$$Cz>>,,";
const output = Array.prototype.reduce.call(input, (res, c) => res + ((c >= 'A' && c <= 'Z') ? c: ""), "");
console.log({ input, output })
Upvotes: 1