Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Replace With Alphabet Position

//codewars :Replace With Alphabet Position
function alphabetPosition(text) {
  var result = "";
  for (var i = 0; i < text.length; i++) {
    var code = text.toUpperCase().charCodeAt(i)
    if (code > 64 && code < 91) result += (code - 64) + " ";
  }

  return result.slice(0, result.length - 1);
}
Comment

Replace With Alphabet Position

function alphabetPosition(text) {
  var result = "";
  for (var i = 0; i < text.length; i++) {
    var code = text.toUpperCase().charCodeAt(i)
    if (code > 64 && code < 91) result += (code - 64) + " ";
  }

  return result.slice(0, result.length - 1);
}
console.log(alphabetPosition("The sunset sets at twelve o' clock."));
Comment

Replace With Alphabet Position

/*
// Given a string, replace every letter with its position in the 
alphabet.
// If anything in the text isn't a letter, ignore it and don't return it.
"a" = 1, "b" = 2, etc.

  Example
  alphabetPosition("The sunset sets at twelve o' clock.")
  Should return "20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11" ( as a string )
*/

const alphabetPosition = text => text.replace(/[d|W|_]/g, "").split("")
			.map(letter => letter.charCodeAt(0) & 31).join(' ');

// With love @kouqhar
Comment

Replace With Alphabet Position

function alphabetPosition(text) {
  
  let alpha = 'abcdefghijklmnopqrstuvwxyz'
  let numbers = []

   text = text.toLowerCase();


  for( let i=0;i<text.length;i++){
    let idx = alpha.indexOf(text[i])

    if(idx === -1){
        continue;
    }else{
        numbers.push(idx +1)
    }
  }
 
   return numbers.join(' ')

  }

 
  


  
  

Comment

PREVIOUS NEXT
Code Example
Javascript :: How to Perform Date Comparison With the Date Object in JavaScript 
Javascript :: format date js 
Javascript :: prevent default jquery 
Javascript :: capitalise first letter js 
Javascript :: radiojquery 
Javascript :: create file if not exists nodejs 
Javascript :: which methods do not have the hook equivalents in reactjs 16.8++ 
Javascript :: unexpected end of json input while parsing near 
Javascript :: TypeError: sequelize.import is not a function 
Javascript :: js capitalize 
Javascript :: foreach javascript 
Javascript :: outer width jquery 
Javascript :: get data from url in angular 
Javascript :: jquery find checkbox by value 
Javascript :: latin science words 
Javascript :: javascript change url 
Javascript :: Javascript get sum of array values 
Javascript :: get last index of array 
Javascript :: jquery find by innertext 
Javascript :: get random entry from array javascript 
Javascript :: get parameters from url 
Javascript :: split url javascript 
Javascript :: react form submit 
Javascript :: js array to csv 
Javascript :: react js image path src from local folder 
Javascript :: emotion react 
Javascript :: MongoNotConnectedError: Client must be connected before running operations 
Javascript :: js string to array 
Javascript :: n javascript 
Javascript :: parse date from string in js 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =