I'm given an array of objects representing data about people. I need to filter names, which when add the ASCII representation of all characters in their first names, the result will be an odd number. e.g.: Sum of ASCII codes of letters in 'Aba' is: 65 + 98 + 97 = 260 which is an even number -- filter it out
My logic is as follows:
- get first names;
- convert each letter of the first name to ASCII code;
- add ASCII codes of each name;
- check, if the received number is odd;
- return names, which ASCII code number is odd.
I've completed 4 tasks of the above, but I do not know, how to connect items from different arrays.
E.g.: I have an array of names: let names = ['Aba', 'Abb'], and array of odd/even numbers: let oddEven = [0, 1].
How can I make:
1) names[0] is oddEven[0]
2) if oddEven[0] > 0 { filter it out } ?
Thanks
my code:
function findOddNames(list) {
let names = list.map((name) => name.firstName);
let splittedNames = names.map((name) => name.split(''));
let charCodes = splittedNames.map((arr) => arr.map((letter) => letter.charCodeAt(0)));
let charCodesTotal = charCodes.map((arr) => arr.reduce((a, b) => a + b, 0));
let oddEven = charCodesTotal.map((item) => item % 2);
};
findOddNames([
{ firstName: 'Aba', lastName: 'N.', country: 'Ghana', continent: 'Africa', age: 21, language: 'Python' },
{ firstName: 'Abb', lastName: 'O.', country: 'Israel', continent: 'Asia', age: 39, language: 'Java' }
])