Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Highest Scoring Word

/*
Given a string of words, you need to find the highest scoring word.
Each letter of a word scores points according to its position in the 
	alphabet: a = 1, b = 2, c = 3 etc.
You need to return the highest scoring word as a string.
If two words score the same, return the word that appears earliest in the 
	original string.
All letters will be lowercase and all inputs will be valid.
*/

const high = x => {
  let word = []
  let scores = []
  
  x.split(" ").forEach(letter => {
    word.push(letter)
    let score = letter.split("")
    .map(alphabet => alphabet.charCodeAt(0) & 31)
    .reduce((acc, cur) => acc + cur, 0)
    scores.push(score)
  })
  
  const index = scores.indexOf(Math.max(...scores))
  return word[index]

}

// With love @kouqhar
Comment

PREVIOUS NEXT
Code Example
Javascript :: creating room in ws node js 
Javascript :: js addeventlistener input search phone 
Javascript :: react native communicate with webview 
Javascript :: export to excel on button click in javascript 
Javascript :: setTimeout() nodejs 
Javascript :: palindrome string js 
Javascript :: res.write in node js 
Javascript :: how to send dm to every member in discord with discord.js 
Javascript :: javascript set() handler 
Javascript :: how to reload automaticaly in vue 
Javascript :: slice() in javascript 
Javascript :: js variable for key obj 
Javascript :: jquery connection reset 
Javascript :: req.body is empty express js 
Javascript :: promises in es6 
Javascript :: how to inspect element attributes in cypress 
Javascript :: graphql buildschema 
Javascript :: what is javascript used for 
Javascript :: react features 
Javascript :: react js charts with camvas 
Javascript :: what is == in js 
Javascript :: get search value from reacr route 
Javascript :: bind this react 
Javascript :: self-invoking function 
Javascript :: nodejs module 
Javascript :: create and get all the files in a directory with nodejs 
Javascript :: puppeteer click element with custom property 
Javascript :: usecontext 
Javascript :: prevent a function from being called too many times react 
Javascript :: jquery get label text only for input 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =