Programming task #1

Programming task #1


Given a string of words, you need to find the word with the highest number of points.

Each letter of a word scores points according to it’s position in the alphabet. a=1, z=26 and everything inbetween. Write a function that will return the word with the highest number of points as a string. If two words score the same, return the word that appears earliest in the original string.All letters will be lower case and all inputs will be valid. There will be no special characters and all words will be separated by a space. For example
function example (‘peanut butter jelly time’) // will return ‘butter’ as the answer


Great idea for a thread/series!

Here’s my answer:

function findHighestPointWord(sentence) {
	const words = sentence.trim().split(/\s+/);
	const wordVals = [];

	words.forEach(function(word) {
		const lcWord = word.toLowerCase();
		let wordVal = 0;
		for (let i = 0; i < word.length; i++) {
			wordVal += lcWord.charCodeAt(i) - 96;
	return words[wordVals.indexOf(Math.max(...wordVals))];


Hello ! Seem cool. Maybe a daily thing to do ? Will maybe take a look later to try out :slight_smile:


I’d love that too. I’m new to programming so you guys would have to help out also. Many Thanks


Wait, are you hoping to make this into a series yourself, or just reposting a question you found elsewhere?


Okay cool I’ll have that in mind. If they could be answered in different languages, it would be great


I’ll make it a series


Ah, I see.

I can help out with writing some tests to check answers, if you like :sunglasses:


Okay cool. no problemo


If you intend this to be a challenge to others, you should also post your own work :wink:

Anyway here’s mine:

function score(word) {
  return [...word].reduce((a, b) => a + b.charCodeAt() - 96, 0);

function wordWithHighestScore(words) {
  const scores =;
  const highestScore = Math.max(...scores);

  return words[scores.indexOf(highestScore)];

wordWithHighestScore(['peanut', 'butter', 'jelly', 'time']);


Lol, I see what you did there @kevcomedia


OK, here are the tests:

To pass, your function must be named findHighestPointWord(), it must take one argument as a string (the sentence), and it must be case insensitive for input (output is case sensitive to the original string). However, it doesn’t need to handle special characters in any intelligent way (just the basic English-language alphabet and spaces).


Lol I wasn’t reading the instructions :sweat_smile: . I thought the input would be an array of strings.

Here’s my revision:

function score(word) {
  return [...word].reduce((a, b) => a + b.toLowerCase().charCodeAt() - 96, 0);

function findHighestPointWord(wordString) {
  const words = wordString.split(' ');
  const scores =;
  const highestScore = Math.max(...scores);

  return words[scores.indexOf(highestScore)];


I think you should add this as a border case:

['ABC cba', 'ABC']

or something like this


Done and done!