<script>
// Javascript implementation to find the index of
// first '1' in a sorted array of 0's and 1's
// function to find the index of first '1'
function indexOfFirstOne(arr, n)
{
// traverse the array from left to right
for (let i = 0; i < n; i++)
// if true, then return i
if (arr[i] == 1)
return i;
// 1's are not present in the array
return -1;
}
// Driver program to test above
let arr = [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ];
let n = arr.length;
document.write(indexOfFirstOne(arr, n));
//This code is contributed by Mayank Tyagi
</script>
<script>
// Javascript implementation to find the index of
// first '1' in a sorted array of 0's and 1's
// function to find the index of first '1'
function indexOfFirstOne(arr, n)
{
// traverse the array from left to right
for (let i = 0; i < n; i++)
// if true, then return i
if (arr[i] == 1)
return i;
// 1's are not present in the array
return -1;
}
// Driver program to test above
let arr = [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ];
let n = arr.length;
document.write(indexOfFirstOne(arr, n));
//This code is contributed by Mayank Tyagi
</script>
<script>
// Javascript implementation to find the index of
// first '1' in a sorted array of 0's and 1's
// function to find the index of first '1'
function indexOfFirstOne(arr, n)
{
// traverse the array from left to right
for (let i = 0; i < n; i++)
// if true, then return i
if (arr[i] == 1)
return i;
// 1's are not present in the array
return -1;
}
// Driver program to test above
let arr = [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ];
let n = arr.length;
document.write(indexOfFirstOne(arr, n));
//This code is contributed by Mayank Tyagi
</script>
<script>
// Javascript implementation to find the index of
// first '1' in a sorted array of 0's and 1's
// function to find the index of first '1'
function indexOfFirstOne(arr, n)
{
// traverse the array from left to right
for (let i = 0; i < n; i++)
// if true, then return i
if (arr[i] == 1)
return i;
// 1's are not present in the array
return -1;
}
// Driver program to test above
let arr = [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ];
let n = arr.length;
document.write(indexOfFirstOne(arr, n));
//This code is contributed by Mayank Tyagi
</script>
<script>
// Javascript implementation to find the index of
// first '1' in a sorted array of 0's and 1's
// function to find the index of first '1'
function indexOfFirstOne(arr, n)
{
// traverse the array from left to right
for (let i = 0; i < n; i++)
// if true, then return i
if (arr[i] == 1)
return i;
// 1's are not present in the array
return -1;
}
// Driver program to test above
let arr = [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ];
let n = arr.length;
document.write(indexOfFirstOne(arr, n));
//This code is contributed by Mayank Tyagi
</script>
<script>
// Javascript implementation to find the index of
// first '1' in a sorted array of 0's and 1's
// function to find the index of first '1'
function indexOfFirstOne(arr, n)
{
// traverse the array from left to right
for (let i = 0; i < n; i++)
// if true, then return i
if (arr[i] == 1)
return i;
// 1's are not present in the array
return -1;
}
// Driver program to test above
let arr = [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ];
let n = arr.length;
document.write(indexOfFirstOne(arr, n));
//This code is contributed by Mayank Tyagi
</script>
<script>
// Javascript implementation to find the index of
// first '1' in a sorted array of 0's and 1's
// function to find the index of first '1'
function indexOfFirstOne(arr, n)
{
// traverse the array from left to right
for (let i = 0; i < n; i++)
// if true, then return i
if (arr[i] == 1)
return i;
// 1's are not present in the array
return -1;
}
// Driver program to test above
let arr = [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ];
let n = arr.length;
document.write(indexOfFirstOne(arr, n));
//This code is contributed by Mayank Tyagi
</script>
<script>
// Javascript implementation to find the index of
// first '1' in a sorted array of 0's and 1's
// function to find the index of first '1'
function indexOfFirstOne(arr, n)
{
// traverse the array from left to right
for (let i = 0; i < n; i++)
// if true, then return i
if (arr[i] == 1)
return i;
// 1's are not present in the array
return -1;
}
// Driver program to test above
let arr = [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ];
let n = arr.length;
document.write(indexOfFirstOne(arr, n));
//This code is contributed by Mayank Tyagi
</script>
<script>
// Javascript implementation to find the index of
// first '1' in a sorted array of 0's and 1's
// function to find the index of first '1'
function indexOfFirstOne(arr, n)
{
// traverse the array from left to right
for (let i = 0; i < n; i++)
// if true, then return i
if (arr[i] == 1)
return i;
// 1's are not present in the array
return -1;
}
// Driver program to test above
let arr = [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ];
let n = arr.length;
document.write(indexOfFirstOne(arr, n));
//This code is contributed by Mayank Tyagi
</script>
<script>
// Javascript implementation to find the index of
// first '1' in a sorted array of 0's and 1's
// function to find the index of first '1'
function indexOfFirstOne(arr, n)
{
// traverse the array from left to right
for (let i = 0; i < n; i++)
// if true, then return i
if (arr[i] == 1)
return i;
// 1's are not present in the array
return -1;
}
// Driver program to test above
let arr = [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ];
let n = arr.length;
document.write(indexOfFirstOne(arr, n));
//This code is contributed by Mayank Tyagi
</script>