ADVERTISEMENT
ADVERTISEMENT

Ruby program to demonstrate the Array.dig() method

Ruby Example: Write a program to demonstrate the Array.dig() method.
Submitted by Nidhi, on January 16, 2022

Problem Solution:

In this program, we will create two arrays of integers. Here, we will use the dig() method which is used to extract the specific element out of the high dimension sequences.

Program/Source Code:

The source code to demonstrate the Array.dig() method is given below. The given program is compiled and executed successfully.

# Ruby program to demonstrate the 
# Array.dig() method

arr1 = [10,21,30,41,50];
arr2 = [[10,20],[10,20,30],[10,20,30,40]];

res = arr1.dig(3);
puts "Result: ",res;

res = arr2.dig(1,2);
puts "Result: ",res;

Output:

Result: 
41
Result: 
30

Explanation:

In the above program, we created two arrays arr1, arr2 with some elements. Then we use the dig() method. The dig() method is used to extract the specific element out of the high dimension sequences. Here, we extracted elements from arr1, arr2 using the dig() method and printed the result.

Ruby Arrays Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.