i work in college radio station, , want way catalogue our physical music numbers. want take artist, release name, , year, , compute 9 digit number.
i have few things coded already.
function bijection(letter) read single character, reference var alpha = ["0","1","2",..."9","a","b",..."x","y","z"], , return index of provided character. so, bijection(c) = 13, example.
function bijection(character){ var alpha = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]; var position = alpha.indexof(character) + 1; return position; }
function easyread(string) take string of characters, , remove spaces. so, easyread("two door cinema club") returns twodoorcinemaclub.
function easyread(noun){ var out = noun.split(' ').join(''); return out; }
function label(number1,number2,number3) take 3 numbers, evaluate each mod 1000, , combine them 9-digit integer. example, label(1001,1002,1003) returns 100200300.
function label(sum1,sum2,year){ var label = 1000000*(sum1%1000) + 1000*(sum2%1000) + year%1000; return label;
i want write function called sigma, take string no spaces, break character character, , add indices. so, i'd run string through easyread, plug sigma, refer bijection in iteration on each character in string, , maths return sum of each bijection(character). take whatever sigma outputs, , have input label. i'm lost on how make sigma happen, though. help?
updates:
this got far.
function sigma(noun){ var domain = easyread(noun) //removes spaces input noun for(let n = 0; n<domain.length; n++) { //start n = 0, , stop when n incrementally larger length of our spaces-removed string. let iterative = domain[n]; //not sure bijection(iterative); //tells computer calculate bijection of each character } //return sum of bijection(iterative), somehow? }
given pretty new javascript
, try best avoid using complex apis.
essentially strip out spaces, have string.replace(...)
. api takes in regular expression pattern. want /\s/g
want "find spaces within string" , 2nd parameter ''
, replace with ''.
after want loop through each characters in spaceless string value, simple for-loop
, on each loop call bijection()
function.
consider code below.
example:
"use strict"; function bijection(char) { // assuming bijection fn console.log("converting character: " + char + " value..." ); return 10; // assuming every character value of 10. } let test = "one may have spaces "; let nospace = test.replace(/\s/g, ""); let totalvalue = 0; for(let n = 0; n < nospace.length; n++) { let char = nospace[n]; totalvalue += bijection(char); } console.log("total value => " + totalvalue);
Comments
Post a Comment