Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Second Index by z.thami
"use strict";
function secondIndex(text, symbol) {
// returns the second index of a symbol in a given text
let start_position = text.indexOf(symbol) + 1;
let second_occurence = text.indexOf(symbol, start_position);
if (second_occurence < 0){
return undefined;
}
return second_occurence;
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example')
console.log(secondIndex("sims", "s"))
console.log(secondIndex("hi", " "))
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(secondIndex("sims", "s"), 3)
assert.equal(secondIndex("find the river", "e"), 12)
assert.equal(secondIndex("hi", " "), undefined)
assert.equal(secondIndex("hi mayor", " "), undefined)
assert.equal(secondIndex("hi mr Mayor", " "), 5)
console.log("You are awesome! All tests are done! Go Check it!");
}
Aug. 6, 2019