1// List of element abrivations in order of atomic number 2const elements = [ 3 "H", "He", 4 "Li", "Be", "B", "C", "N", "O", "F", "Ne", 5 "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", 6 "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", 7 "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", 8 "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", 9 "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Nh", "Fl", "Mc", "Lv", "Ts", "Og" 10]; 11 12const alkali = [3, 11, 19, 37, 55, 87]; 13const alkaliEarth = [4, 12, 20, 38, 56, 88]; 14const lanthanoid = [57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 79, 70, 71]; 15const actinoid = [89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103]; 16const transition = [21,22,23,24,25,26,27,28,29,30,39,40,41,42,43,44,45,46,47,48,72,73,74,75,76,77,78,79,80,104,105,106,107,108]; 17const postTransition = [13, 31, 49, 50, 81, 82, 83, 84]; 18const metalloid = [5, 14, 32, 33, 51, 52, 85]; 19const reactiveNonmetal = [1, 6, 7, 8, 9, 15, 16, 17, 34, 35, 53] 20const noble = [2, 10, 18, 36, 54, 86] 21const space = [elements.length+1] 22 23 24// Function which returns a boolean based on whether input string can be spelled using periodic table abriviations 25function periodicMatch(string, allowSpaces = false) { 26 let matchStrings = []; 27 elements.forEach(item=>matchStrings.push(item.toUpperCase())); 28 if (allowSpaces) { 29 matchStrings.push(" "); 30 }; 31 32 const regex = new RegExp("^((" + matchStrings.join(")|(") + "))+$", "g"); 33 34 return string.toUpperCase().match(regex) != null; 35} 36 37 38// Function which returns an array of objects with each object containing a string of the spelling, and the atomic numbers of elements used in the spelling (or 119 for space) 39function periodicSpell(string, allowSpaces = false) { 40 let matchStrings = Array.from(elements); 41 if (allowSpaces) { 42 matchStrings.push(" "); 43 }; 44 45 let listA = [{nums: [], length:0, string:''}] 46 47 48 while (true) { 49 let listB = []; 50 51 listA.forEach(test => { 52 if (test.string.toUpperCase() == string.toUpperCase()) { 53 listB.push(test) 54 return 55 } 56 57 matchStrings.forEach((matchString, n) => { 58 if (test.length + matchString.length > string.length) 59 return 60 if (matchString.toUpperCase() == string.toUpperCase().slice(test.length, test.length + matchString.length)) { 61 let outputNums = Array.from(test.nums) 62 outputNums.push(n+1); 63 listB.push({nums: outputNums, length:test.length + matchString.length, string: test.string + matchString}) 64 } 65 }); 66 }); 67 68 if (JSON.stringify(listA) == JSON.stringify(listB)) { 69 listA.forEach((item, i, array) => { 70 delete item.length; 71 }); 72 73 return listA; 74 break 75 } 76 77 listA = Array.from(listB); 78 } 79} 80
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.