Theme images by Storman. Powered by Blogger.

Monday 11 February 2019

Find the min/max element of an Array in JavaScript

- No comments

I have just figured out some great way to find the min and max value from the array and I just wanted to share with all of you.

See the code below, use it or add console log to understand it in depth.




var arr = [12, 89, 67, 55];

// Method 1
function arrayMax(arr) {
return arr.reduce(function(p, v) {
return Math.max(p, v); // Math.min for min
});
}
arrayMax(arr);

// Method 2
function arrayMax(arr) {
return arr.reduce(function(p, v) {
return p > v ? p : v; // p < v for min
});
}
arrayMax(arr);

// Method 3
Math.max(...arr); // Math.min for min

// Method 4
function findMinMax(arr) {
let min = arr[0],
max = arr[0];

for (let i = 1, len = arr.length; i < len; i++) {
let v = arr[i];
min = v < min ? v : min;
max = v > max ? v : max;
}
return [min, max];
}

findMinMax(arr);

Thursday 7 February 2019

Bootstrap Custom Theme in react Application

- 1 comment




"Bootstrap" as every developer knows a very popular framework for the CSS and, comes with its build in components, styles and utilities.

Recently I was using bootstrap for one of my react project. but bootstrap comes with its own default styles and I was looking for some mechanism so I can use my own styles or putting into the simple way I can customize the bootstrap styles.

During this process, I figured out the solution, In this post, In a few easy steps I am going to share how you can customize bootstrap.

STEP 1:

Include bootstrap in your application
           

  npm install --save bootstrap



STEP 2:

To customize Bootstrap, create a file called src/custom.scss(decide the place where you want to keep your custom.scss file) and alter the value of the variable you want to customize.


// Override default variables before the import
$primary: #000;

// Import Bootstrap and its default variables
@import '~bootstrap/scss/bootstrap.scss';


You can see all the available variables inside bootstrap\scss\_variables.scss and you can select the one which you want to modify.


STEP 3 :

Import the newly created .scss file instead of the default Bootstrap .css in the beginning of your src/index.js file, for example:


import './customCss/custom.scss';



And its done. Run your react project and see the magic.


Thanks for reading; if you find it useful or something you want to add do comment.

Happy Learning :-)