Created
September 10, 2020 14:46
-
-
Save masao/c594344ff5f4b074812f4b3b74db6b7b to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/ziliwih
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<textarea id="list" rows="15" cols="30" style="width:100%"></textarea><br> | |
<button onclick="javascript:convert();"> | |
Convert | |
</button> | |
<script id="jsbin-javascript"> | |
function convert() { | |
var list = document.getElementById("list") | |
var output = "" | |
var lines = list.value.split(/\r?\n/) | |
console.log(lines) | |
lines.forEach(function(line){ | |
var numbers = line.split(/;/) | |
if (numbers) { | |
numbers.forEach(function(number_s){ | |
var years = number_s.match(/\d+-\d+|\d+/g) | |
console.log(years) | |
if (years) { | |
years.forEach(function(range){ | |
var range_s = range.split(/-/); | |
if (range_s.length == 2) { | |
for (var i = range_s[0]; i <= range_s[1]; i++) { | |
output += i + " "; | |
} | |
} else { | |
output += range_s[0] + " " | |
} | |
}) | |
} | |
}) | |
} | |
output += "\n"; | |
}); | |
list.value = output; | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function convert() { | |
var list = document.getElementById("list") | |
var output = "" | |
var lines = list.value.split(/\r?\n/) | |
console.log(lines) | |
lines.forEach(function(line){ | |
var numbers = line.split(/;/) | |
if (numbers) { | |
numbers.forEach(function(number_s){ | |
var years = number_s.match(/\d+-\d+|\d+/g) | |
console.log(years) | |
if (years) { | |
years.forEach(function(range){ | |
var range_s = range.split(/-/); | |
if (range_s.length == 2) { | |
for (var i = range_s[0]; i <= range_s[1]; i++) { | |
output += i + " "; | |
} | |
} else { | |
output += range_s[0] + " " | |
} | |
}) | |
} | |
}) | |
} | |
output += "\n"; | |
}); | |
list.value = output; | |
} | |
</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convert() { | |
var list = document.getElementById("list") | |
var output = "" | |
var lines = list.value.split(/\r?\n/) | |
console.log(lines) | |
lines.forEach(function(line){ | |
var numbers = line.split(/;/) | |
if (numbers) { | |
numbers.forEach(function(number_s){ | |
var years = number_s.match(/\d+-\d+|\d+/g) | |
console.log(years) | |
if (years) { | |
years.forEach(function(range){ | |
var range_s = range.split(/-/); | |
if (range_s.length == 2) { | |
for (var i = range_s[0]; i <= range_s[1]; i++) { | |
output += i + " "; | |
} | |
} else { | |
output += range_s[0] + " " | |
} | |
}) | |
} | |
}) | |
} | |
output += "\n"; | |
}); | |
list.value = output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment