Given two strings, find the number of common characters between them.
For s1 = "aabcc"
and s2 = "adcaa"
, the output should be
commonCharacterCount(s1, s2) = 3
.
Strings have 3 common characters - 2 "a"s and 1 "c".
// https://github.com/Stuk/jszip/issues/399 | |
JSZip.loadAsync(data).then(function (zip) { | |
var re = /(.jpg|.png|.gif|.ps|.jpeg)$/; | |
var promises = Object.keys(zip.files).filter(function (fileName) { | |
// don't consider non image files | |
return re.test(fileName.toLowerCase()); | |
}).map(function (fileName) { | |
var file = zip.files[fileName]; | |
return file.async("blob").then(function (blob) { |
const numberOfCharInString = (c, s) => { | |
let [count, index] = [0, 0]; | |
while (true) { | |
index = s.indexOf(c, index); | |
if (index >= 0) { | |
++count; | |
++index; | |
} else break; | |
} | |
return count; |
# https://www.tutorialspoint.com/csharp/index.htm | |
# https://www.dotnetperls.com/ |
import grass.script as grass | |
grass.run_command('r.viewshed', | |
input='standard.dem', | |
output='viewshed', | |
coordinate=[observer_x, observer_y], | |
obs_elev=1.75, | |
tgt_elev=0.0, | |
memory=4098, | |
overwrite=True, |
Two arrays are called similar if one can be obtained from another by swapping at most one pair of elements in one of the arrays.
Given two arrays a and b, check whether they are similar.
For a = [1, 2, 3]
and b = [1, 2, 3]
, the output should be
areSimilar(a, b) = true
.
The arrays are equal, no need to swap any elements.
import arcpy | |
vector_file = os.path.join(r"/path/to/feature/class") | |
field_names = [f.name for f in arcpy.ListFields(vector_file)] | |
field_names | |
# [u'FID', u'Shape', u'Id'] |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Previous/Next Extent</title> | |
<meta charset="utf-8"> | |
<link rel="stylesheet" href="//js.arcgis.com/3.21/esri/css/esri.css"> | |
<style> | |
html, body { | |
margin: 0; padding: 0; | |
width: 100%; height: 100%; |
Find the leftmost digit that occurs in a given string.
inputString = "var_1__Int"
, the output should befirstDigit(inputString) = '1'
;inputString = "q2q-q"
, the output should befirstDigit(inputString) = '2'
;inputString = "0ss"
, the output should befirstDigit(inputString) = '0'
.