Skip to main content

JavaScript Hash function

 java Script hash 

code for genrating sam number as 
function hashCode(string) {
    let hash = 0;
    if (string.length == 0) {
        return hash;
    }
    for (let i = 0; i < string.length; i++) {
        let char = string.charCodeAt(i);
        hash = ((hash<<5)-hash)+char;
        hash = hash & hash;
    }
    return hash;
}

let input = document.querySelector("#input")
let output = document.querySelector("#output")

input.addEventListener("keyup", () => {
  output.value = hashCode(input.value)
})

html

<p>Enter text here</p>
<input type="text" id="input">

<p>'Random' number outputted here</p>
<input type="text" disabled="disabled" value="" id="output">

Comments

Popular posts from this blog

Node JS Express

 Node Js Express npm & Installation npm init npm i express Require // organization of a project const express = require ( "express" ); const compression = require ( "compression" ); const cookieParser = require ( "cookie-parser" ); const csrf = requrie ( "csurf" ); const morgan = require ( "morgan" ); const multer = require ( "multer" ); Initilasation Express const  app = express(); EJS COde app.use( "/static" , path.join(__dirname,  "static" )); app.set( "view engine" ,  "ejs" ); app.set( "views" , path.join(__dirname,  "/views" )); BOdy Post  app.use(express .urlencoded({ extended : true })); Routes  //routers for nav bar ......... app.get( "/" ,(req,res) => {     res.send( "you are at now Home" ) }) app.get( "/about" ,(req,res) => {     res.send( "About Us" ) }) app.get( "/Contect"

Summernote Text Editor

  <! DOCTYPE html > < html >     < head >         < meta charset = "utf-8" >         < meta http-equiv = "X-UA-Compatible" content = "IE=edge" >         < title >compose Blog</ title >         < meta name = "description" content = "" >         < meta name = "viewport" content = "width=device-width, initial-scale=1" >           <!-- CSS only -->         < link rel = "stylesheet" href = "/dashCss/main.css" >         < link rel = "stylesheet" href = "/dashCss/createBlog.css" >           <!-- tailwindcss -->         <!-- <script src="https://cdn.tailwindcss.com"></script> -->           <!-- summarnote cdn -->     < link href = "https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.css" rel = "stylesheet" >